gpt4 book ai didi

c# - IIS - 创建新网站抛出异常

转载 作者:太空宇宙 更新时间:2023-11-03 16:40:15 25 4
gpt4 key购买 nike

运行以下代码:

DirectoryEntry w3svc = new DirectoryEntry("IIS://localhost/w3svc");
int siteId = GetUniqueSiteId(Path);
private string DEFAULT_WEB_SITE_PHYSICAL_PATH = System.IO.Path.GetPathRoot(Environment.SystemDirectory) + @"inetpub\wwwroot";

object[] newsite = new object[] { "Default Web Site", new object[] { ":80:" }, DEFAULT_WEB_SITE_PHYSICAL_PATH, siteId };

w3svc.Invoke("CreateNewSite", newsite);

抛出以下异常:

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Runtime.InteropServices.COMException (0x800700B7): Cannot create a file when that file already exists. (Exception from HRESULT: 0x800700B7)

我试图仅在“默认网站”不存在时运行此代码。只有在 Windows Server 2003 中运行时才会引发异常。此外,当在每次失败后重试并休眠 1 秒的循环中运行此代码时,该代码最终会在 3 次重试后运行并创建默认网站。

谁知道可能是什么原因?

最佳答案

当“默认网站”存在时,您正试图创建“默认网站”。你自己说当网站不存在时它工作正常......

关于c# - IIS - 创建新网站抛出异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7804808/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com