新创建的应用程序池未在IIS管理器中显示。

huangapple go评论66阅读模式
英文:

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

新创建的应用程序池未在IIS管理器中显示。

英文:

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

新创建的应用程序池未在IIS管理器中显示。

答案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.

    &lt;Reference Include=&quot;Microsoft.Web.Administration, Version=7.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL&quot;&gt;
      &lt;SpecificVersion&gt;True&lt;/SpecificVersion&gt;
      &lt;HintPath&gt;%windir%\Windows\System32\inetsrv\Microsoft.Web.Administration.dll&lt;/HintPath&gt;
    &lt;/Reference&gt;

huangapple
  • 本文由 发表于 2023年6月9日 06:04:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/76435992.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定