简体   繁体   中英

Create an application under default web site IIS

I am trying to create a new application under default web site by using C# code. This is what I tried

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;
        }
    }

But getting path already exists error can some one help me.

How can we set directory browsing enabled

You could try to use below command to set directory browsing enabled.

        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();

Result:

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM