我正在尝试更改ASP.NET临时文件的位置,以便在发布新版本时清理这些文件。
因为很难找到特定网站的ASP.NET临时文件的位置,所以我决定将文件移动到磁盘上的特定位置,然后清理虚拟目录下的应用程序。
您可以通过修改system.web/compilation
配置节中的tempDirectory属性来完成此操作。
我们的服务器构建和发布流程是自动化的,因此,将代码添加到配置和发布脚本中看起来很简单。
然而,在测试过程中,我发现32位应用程序的位置没有改变。
我使用的代码是:
Set-WebConfigurationProperty -pspath 'MACHINE/WEBROOT' -location 'MyWebSite' -filter 'system.web/compilation' -name 'tempDirectory' -value 'E:\Temporary ASP.NET Files\MyWebSite' -Clr v2.0
这段代码正常工作,并将一个条目写入根web.config文件,其位置为:C:\Windows\Microsoft.NET\Framework64\v2.0.50727\CONFIG\web.config
.
例如:
<location path="MyWebSite">
<system.web>
<compilation tempDirectory="E:\Temporary ASP.NET Files\MyWebSite" />
</system.web>
</location>
请注意,如果没有-Clr v2.0参数,该值将写入CLR 4.0配置文件中的C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\web.config
位置。
您也可以在IIS配置编辑器中看到该条目:x1c 0d1x
问题是应用程序池设置为“启用32位应用程序”,因此忽略了此属性。
如果我手动将上面显示的location元素从C:\Windows\Microsoft.NET\Framework64\v2.0.50727\CONFIG\web.config
移动到C:\Windows\Microsoft.NET\Framework\v2.0.50727\CONFIG\web.config
更改起作用,实际上ASP.NET临时文件会移动到网站编译时指定的位置。
这个问题不是关于ASP.NET临时文件的,而是一个更一般的问题,即如何在PowerShell或IIS中配置32位应用程序?似乎没有办法做到这一点,我觉得不可思议。有很多32位应用程序仍然需要配置。
还请注意,我选择使用根web.config来存储此值是有充分理由的:
ApplicationHost.config
无法存储system.web
配置
1.临时文件的位置在设计时是未知的,由宿主服务器配置确定。因此,不能在应用程序本身的web.config
文件中指定此设置。
2条答案
按热度按时间vwkv1x7d1#
有两种解决方法。
1.请使用32比特的appcmd.exe。范例如下。
设置配置-节:应用程序设置/+"[键=“测试”,值=“测试”]”/commit:webroot /clr:4.0
1.直接在powershell上使用MWA。下面是一个示例。
在此基础上,本文提出了一种新的Web服务器配置方法,该方法包括以下步骤:
v6ylcynt2#
经过实验,使用此处提供的答案中的一些信息和脱机对话,我可以得出结论:使用Microsoft WebAdministration PowerShell cmdlet编辑32位根web.config文件 -是不可能的*。
看起来cmdlet被硬编码为只查看64位版本的配置文件。IIS管理器的行为也是如此。我无法解释为什么会出现这种情况。
我还发现使用一些cmdlet编辑64位Clr 2.0网站和应用程序时存在很多问题。Clr参数并不存在于所有cmdlet上,即使在有Clr参数的cmdlet中,它似乎也不总是工作。
因此,我决定放弃WebAdministration cmdlet,直接使用“Microsoft.Web.Administration.dll”程序集和Microsoft.Web.Administration.ServerManager对象。
下面是我编写的一些函数,可能会有帮助: