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



下午好,请您好心的帮助专家,目前我正在使用Microsoft.Web.Administration.ServerManager库开发一个用于在IIS中自动创建网站的应用程序,网站和应用程序池已正确创建,但创建的网站没有,它是用所有功能创建的,它只是用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$WindowsSystem32inetsrvconfigapplicationHost.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$WindowsSystem32inetsrvconfigapplicationHost.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();
}
}


}

手动创建的站点

自动创建的站点

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

相关内容

最新更新