web.config中system.webServer对应compilation.tempDirectory等效配置
解答
system.web > compilation[tempDirectory]不存在system.webServer节点下的等效配置项,二者职责完全独立,不存在替代关系:
system.web节点负责ASP.NET (.NET Framework) 托管运行时的内部行为配置,编译临时目录属于ASP.NET运行时动态编译逻辑的配置项,仅在该节点下生效system.webServer节点仅负责IIS服务层面的配置(含压缩、URL重写、模块注册、处理程序映射等),不涉及ASP.NET运行时的内部逻辑,没有对应的编译临时目录配置参数。
你之前添加配置触发500错误,并非因为system.web和system.webServer节点不能共存——<configuration>根节点下本来就支持同时挂载这两个同级节点,报错通常是两个原因导致:要么你把compilation节点错放到了system.webServer节点内部,要么你指定的临时目录没有给IIS应用池运行账号授予对应读写权限。
正确配置示例
直接在现有配置中,把system.web节点作为configuration的直接子节点,和system.webServer同级放置即可,完整配置如下:
<?xml version="1.0" encoding="utf-8"?> <configuration> <system.web> <compilation tempDirectory="W:\vhosts\mysite.com\tmp" /> </system.web> <system.webServer> <urlCompression doDynamicCompression="true" doStaticCompression="true" dynamicCompressionBeforeCache="true"/> <rewrite> <rules> <rule name="Angular Routes" stopProcessing="true"> <match url=".*" /> <conditions logicalGrouping="MatchAll"> <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> </conditions> <action type="Rewrite" url="./index.html" /> </rule> </rules> </rewrite> </system.webServer> </configuration>
注意事项
- 配置完成后,需要给目标临时目录
W:\vhosts\mysite.com\tmp授予应用程序池对应标识(默认为IIS AppPool\你的应用池名称,若你修改过池身份则为你设置的运行账号)的读取、写入、修改权限,否则ASP.NET运行时无法写入临时编译文件,依然会抛出服务错误 - 如果你部署的是ASP.NET Core应用,该
compilation配置本身不会生效,ASP.NET Core不使用传统.NET Framework的动态编译机制,不需要配置该临时目录 - 严禁将
compilation节点放到system.webServer节点内部,IIS无法识别该节点下的这个配置项,会直接抛出配置解析错误导致500响应
内容的提问来源于stack exchange,提问作者Yann
相关产品推荐
相关产品推荐

