如何在web.config中配置httpErrors
元素以基于抛出的特定HTTP错误显示通用错误页面?配置httpErrors元素以显示通用错误页面
我使用的是ASP.NET MVC 4
和.NET 4.5
。
我已经在我的web应用程序的根目录下的以下文件:
403.html
404.html
500.html
我在我的web.config以下设置:
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<httpErrors errorMode="Custom">
<remove statusCode="403" />
<remove statusCode="404" />
<remove statusCode="500" />
<error statusCode="403" path="403.html" responseMode="File" />
<error statusCode="404" path="404.html" responseMode="File" />
<error statusCode="500" path="500.html" responseMode="File" />
</httpErrors>
</system.webServer>
我测试上面做类似的东西这个:
throw new System.Web.HttpException(403, "403");
这对我来说很完美,正确的HTML文件显示基于其中之一上面提到的HTTP错误。
我想离开上述HTML文件,而是显示在我的Views/Shared
文件夹中找到的通用错误页面。它被称为Error.cshtml
。我不知道如何改变上面显示这个新的错误页面?
我已经设置了existingResponse
到Auto
,Replace
和PassThrough
但它只是显示一个白页。我已将path
更改为诸如path="/Error"
和path="Views/Shared/Error"
之类的几个变体,这也行不通。
你尝试创建一个errorcontroller /动作,返回错误查看和更改路径,行动? –
是的,但我需要这样做,以便我可以迎合IIS错误。 –