Powershell、IIS Express、Server 2012、Microsoft.Web.Administration 需要以管理员身份运行

Powershell、IIS Express、Server 2012、Microsoft.Web.Administration 需要以管理员身份运行

我在 IISExpress 的 Microsoft.Web.Adminstration 7.9.0.0 上遇到了一个奇怪的问题,需要在 Server 2012 上以管理员身份运行。

我正在尝试使用 powershell 将网站添加到自定义 ApplicationHost.config 文件中。

我已经在 Windows 10 和 Windows 8.1 上测试了我的 powershell 脚本,并且两者都可以在没有管理员的情况下运行,但我只能使用 Server 2012。

我认为这可能与 DLL 版本 IE 7.0.0.0 和 7.9.0.0 之间的冲突有关。

我已将 DLL 添加到文件旁边,但 Add-Type 仍从 GAC 加载它。非常烦人。

我现在唯一能想到的就是:存在某种 GAC 权限问题。这毫无道理。

# Copied the DLL from C:\Windows\assembly\GAC_MSIL\Microsoft.Web.Administration\7.9.0.0__31bf3856ad364e35\Microsoft.Web.Administration.dll
$assemblyPath = "{Path to dll}\Microsoft.Web.Administration.dll"
Add-Type -LiteralPath $assemblyPath

# This shows Microsoft.Web.Administration loading from the GAC. 
[appdomain]::currentdomain.getassemblies()

$iisApplicationConfig = $(Resolve-Path "{Path to applicationhost.config}\applicationhost.config")
$serverManager = New-Object -TypeName Microsoft.Web.Administration.ServerManager -ArgumentList @($iisApplicationConfig)
$site = $serverManager.Sites[$BuildDefaultProjectName]

答案1

我可以告诉你是什么迫使它使用 7.9.0.0

看看这里:C:\Program Files (x86)\IIS Express\config\templates\PersonalWebServer\aspnet.config

有一个重定向。

<dependentAssembly>
<assemblyIdentity name="Microsoft.Web.Administration"
publicKeyToken="31bf3856ad364e35"
culture="neutral" />
<bindingRedirect oldVersion="7.0.0.0"
newVersion="7.9.0.0" />
<codeBase version="7.9.0.0"
href="FILE://%FalconBin%/Microsoft.Web.Administration.dll" />
</dependentAssembly>

您可以直接尝试完整的 IIS 管理包 https://www.nuget.org/packages/Microsoft.Web.Administration

相关内容