问题描述
我试图设置自定义404错误页面,我的Web应用程序。麻烦的是,这个应用程序将被部署到许多不同的环境。有时候,它会在一个虚拟目录,有时不会。
我有一个目录中称为ErrorPages错误页面,并建立了我的配置是这样的:
< httpErrors errorMode =自定义existingResponse =替换>
<清除状态code =404/>
<错误状态code =404路径=/ VirtualDir / ErrorPages / 404.aspxresponseMode =ExecuteURL/>
< / httpErrors>
< /system.webServer>
麻烦的是,当我部署此一网站/ VirtualDir部分需要删除的根源。如果我在部署之前删除它,然后我需要添加回部署到VirtualDirectory时英寸有什么办法,我可以设置路径是相对于VirtualDirectory而不是网站?
我已经使用了〜试过但这也不管用,是这样的:
< httpErrors errorMode =自定义existingResponse =替换>
<清除状态code =404/>
<错误状态code =404路径=〜/ ErrorPages / 404.aspxresponseMode =ExecuteURL/>
< / httpErrors>
< /system.webServer>
您可以使用的web.config转换来设置每个环境的路径:
的web.config
< httpErrors errorMode =自定义existingResponse =替换>
<清除状态code =404/>
<错误状态code =404路径=/ VirtualDir / ErrorPages / 404.aspxresponseMode =ExecuteURL/>
< / httpErrors>
web.Release.config
< httpErrors>
<错误状态code =404路径=/ ErrorPages / 404.aspxesponseMode =ExecuteURL/>
< / httpErrors>
I'm trying to set a custom 404 error page for my web application. The trouble is that this application will be deployed to a number of different environments. Sometimes it will be in a virtual directory and sometimes it won't.
I have the error page in a directory called ErrorPages and have set up my config like this:
<httpErrors errorMode="Custom" existingResponse="Replace">
<remove statusCode="404"/>
<error statusCode="404" path="/VirtualDir/ErrorPages/404.aspx" responseMode="ExecuteURL" />
</httpErrors>
</system.webServer>
The trouble is when I deploy this to the root of a web site the /VirtualDir part needs to be removed. If I remove it before deployment then I need to add it back in when deploying to a VirtualDirectory. Is there any way I can set the path to be relative to the VirtualDirectory and not the site?
I have tried using a ~ but that does not work either, like this:
<httpErrors errorMode="Custom" existingResponse="Replace">
<remove statusCode="404"/>
<error statusCode="404" path="~/ErrorPages/404.aspx" responseMode="ExecuteURL" />
</httpErrors>
</system.webServer>
You could use web.config transforms to set the path per environment:
web.config
<httpErrors errorMode="Custom" existingResponse="Replace">
<remove statusCode="404"/>
<error statusCode="404" path="/VirtualDir/ErrorPages/404.aspx" responseMode="ExecuteURL" />
</httpErrors>
web.Release.config
<httpErrors>
<error statusCode="404" path="/ErrorPages/404.aspx" esponseMode="ExecuteURL" />
</httpErrors>
这篇关于是否有可能在IIS7设置自定义错误页时使用相对路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!