Issue
Good afternoon, please your kind help experts, at the moment I am developing an application for the automatic creation of websites in IIS using the Microsoft.Web.Administration.ServerManager library, the sites and application pools are created correctly but the created site does not it is created with all the features, it is only created with IIS and Management, if I manually create the sites if they are created with all the features (IIS, Asp.Net and management).
I attach a portion of my code and screenshots of the 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();
}
}
}
Solution
I was able to find the solution, it was very simple, I did it by comparing how the app pool was being created in the file with an existing one and the value of newPool.ManagedRuntimeVersion = "V4.0", it is misspelled, it must be with v in miniscule.
Answered By – Erick Salinas
Answer Checked By – Mary Flores (BugsFixing Volunteer)