问题 Asp.net C#- 使用 Microsoft.Web.Administration.ServerManager 创建网站

Problem Asp.net C#- Creating Websites Using Microsoft.Web.Administration.ServerManager

下午好,请专家帮忙,目前我正在开发一个应用程序,用于在 IIS 中使用 Microsoft.Web.Administration.ServerManager 库自动创建网站,网站和应用程序池已正确创建,但已创建网站不是用所有功能创建的,它只是用 IIS 和管理创建的,如果我手动创建网站,如果它们是用所有功能创建的(IIS、Asp.Net 和管理)。 附上我的部分代码和IIS的截图

private void ValidateorCreateWebsiteDumpExist(string serverAddress)
    {
        if (!Directory.Exists(ApiEnviromentPath.Replace("{serverAddress}", serverAddress, StringComparison.InvariantCulture)))
        {
            Directory.CreateDirectory(ApiEnviromentPath.Replace("{serverAddress}", serverAddress, StringComparison.InvariantCulture));

            copyDirectory(ApiEnviromentBinaries,ApiEnviromentPath.Replace("{serverAddress}", serverAddress, StringComparison.InvariantCulture));

        }
        else
        {
            copyDirectory(ApiEnviromentBinaries,ApiEnviromentPath.Replace("{serverAddress}", serverAddress, StringComparison.InvariantCulture));
        }
        ApplicationPool newPool = null;
        using (ServerManager serverManager = new ServerManager(@$"\{serverAddress}\c$\Windows\System32\inetsrv\config\applicationHost.config"))
        {
            if (!serverManager.ApplicationPools.Where(x => x.Name == ApiEnviromentPoolName).Any())
            {
                newPool = serverManager.ApplicationPools.Add(ApiEnviromentPoolName);
                newPool.AutoStart = true;
                newPool.ManagedRuntimeVersion = "V4.0";
                newPool.ProcessModel.IdentityType = ProcessModelIdentityType.SpecificUser;
                newPool.ProcessModel.UserName = ApiEnviromentPoolUserName;
                newPool.ProcessModel.Password = ApiEnviromentPoolPassword;
                newPool.Enable32BitAppOnWin64 = true;
                newPool.ManagedPipelineMode = ManagedPipelineMode.Integrated;
                serverManager.CommitChanges();
            }
        }

        using (var iisManager = new ServerManager(@$"\{serverAddress}\c$\Windows\System32\inetsrv\config\applicationHost.config"))
        {
            if (!iisManager.Sites.Where(x => x.Name == ApiEnviromentSiteName).Any())
            {
                var sites = iisManager.Sites.Add(ApiEnviromentSiteName, ApiEnviromentPath.Replace("{serverAddress}", serverAddress, StringComparison.InvariantCulture), Convert.ToInt32(ApiEnviromentSitePort, CultureInfo.InvariantCulture));
                iisManager.Sites[ApiEnviromentSiteName].Applications[0].ApplicationPoolName = ApiEnviromentPoolName;
                sites.ServerAutoStart = true;
                iisManager.CommitChanges();
            }
        }

        



    }

Manually Created Site

Site created automatically

我找到了解决方案,它非常简单,我通过比较应用程序池在文件中的创建方式与现有应用程序池的方式以及 newPool.ManagedRuntimeVersion = "V4. 0", 拼错了,一定是小写的v.