英文:
Newly Created Application Pool Does Not Appear in IIS Manager
问题
我正在尝试使用以下代码在我的本地计算机上创建一个IIS应用程序池。看起来运行正常,但当我尝试在IIS管理器中查找应用程序池时,似乎找不到它。
当我尝试使用相同的名称创建应用程序池时,出现错误,指示应用程序池已存在。如何正确添加一个在IIS管理器中可见的应用程序池呢?
using Microsoft.Web.Administration;
public static void CreateNewAppPool(string newAppPoolName)
{
try
{
using (ServerManager serverManager = new ServerManager())
{
ApplicationPool newAppPool = serverManager.ApplicationPools.Add(newAppPoolName);
newAppPool.ManagedRuntimeVersion = "v4.0";
newAppPool.ManagedPipelineMode = ManagedPipelineMode.Integrated;
newAppPool.AutoStart = true;
serverManager.CommitChanges();
}
}
catch (Exception ex)
{
Console.WriteLine($"出现错误 - {ex.Message}");
}
}
英文:
I'm trying to create an IIS application pool on my local machine using the below code. It seems like it runs fine, but when I go to look for the application pool in the IIS Manager, I can't seem to find it.
When I try to create an application pool with the same name, I'm given an error stating that the application pool already exists. What is the correct way to add an application pool that is visible in the IIS Manager?
using Microsoft.Web.Administration;
public static void CreateNewAppPool(string newAppPoolName)
{
try
{
using (ServerManager serverManager = new ServerManager())
{
ApplicationPool newAppPool = serverManager.ApplicationPools.Add(newAppPoolName);
newAppPool.ManagedRuntimeVersion = "v4.0";
newAppPool.ManagedPipelineMode = ManagedPipelineMode.Integrated;
newAppPool.AutoStart = true;
serverManager.CommitChanges();
}
}
catch (Exception ex)
{
Console.WriteLine($"Error occured - {ex.Message}");
}
}
答案1
得分: 1
感谢@LexLi提供的提示,我能够找到Microsoft.Web.Administration 7.9.0.0以针对IIS Express。在我的项目设置中将引用版本更改为7.0.0.0之后,我现在能够运行我的代码并在IIS Manager中找到新创建的应用程序池。
<Reference Include="Microsoft.Web.Administration, Version=7.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>True</SpecificVersion>
<HintPath>%windir%\Windows\System32\inetsrv\Microsoft.Web.Administration.dll</HintPath>
</Reference>
英文:
Thanks to the hint provided by @LexLi, I was able to find out that Microsoft.Web.Administration 7.9.0.0 targets IIS Express. After changing the reference version to 7.0.0.0 in my project settings, I'm now able to run my code and find the newly created application pool in the IIS Manager.
<Reference Include="Microsoft.Web.Administration, Version=7.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>True</SpecificVersion>
<HintPath>%windir%\Windows\System32\inetsrv\Microsoft.Web.Administration.dll</HintPath>
</Reference>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论