在默认网站IIS下创建应用程序

时间:2019-10-24 14:25:16

标签: c# iis

我正在尝试使用C#代码在默认网站下创建一个新应用程序。这就是我尝试过的

public static bool CreateWebSite(Application application)
    {
        try
        {
            application.Alias = "Test";
            application.PhysicalPath = @"C:\Test";
            application.ApplicationPool = "TestAppPool";
            using (ServerManager serverManager = new ServerManager())
            {
                serverManager.Sites["Default Web Site"].Applications.Add("/", application.PhysicalPath);
               serverManager.CommitChanges();
            }
            return true;
        }
        catch (Exception se)
        {
            throw se;
        }
    }

但是遇到path already exists错误可以帮助我。

1 个答案:

答案 0 :(得分:0)

  

我们如何设置目录浏览已启用

您可以尝试使用以下命令将目录浏览设置为启用。

        ServerManager server = new ServerManager();

        Configuration config = server.GetWebConfiguration("TestMVC");

        ConfigurationSection directoryBrowseSection = config.GetSection("system.webServer/directoryBrowse");
        directoryBrowseSection["enabled"] = true;
        directoryBrowseSection["showFlags"] = @"Date, Time, Size, Extension";

        server.CommitChanges();

结果:

enter image description here

相关问题