C# asp.net mvc中的自定义错误建议
我有一个应用程序,其中我在web配置文件中使用自定义错误。对于404500403错误状态,它工作正常,如果发现上述错误,则重定向到错误页。但我的问题是,如果我得到的对象引用未设置为对象的实例,并且出现空错误异常或被零除异常,则不会重定向到错误页。有吗非常感谢您的建议。我已经尝试了以下代码C# asp.net mvc中的自定义错误建议,c#,C#,我有一个应用程序,其中我在web配置文件中使用自定义错误。对于404500403错误状态,它工作正常,如果发现上述错误,则重定向到错误页。但我的问题是,如果我得到的对象引用未设置为对象的实例,并且出现空错误异常或被零除异常,则不会重定向到错误页。有吗非常感谢您的建议。我已经尝试了以下代码 enter code here <customErrors mode="On" defaultRedirect="~/Error/Index"> <error statusCode="40
enter code here <customErrors mode="On" defaultRedirect="~/Error/Index">
<error statusCode="404" redirect="~/Error/Index"/>
<error statusCode="403" redirect="~/Error/Index"/>
<error statusCode="500" redirect="~/Error/Index"/>
</customErrors>
在此处输入代码
除了在system.web中添加自定义错误外,还应在webserver中启用自定义错误
<system.webServer>
<httpErrors errorMode="Custom" existingResponse="Auto">
<remove statusCode="403" />
<remove statusCode="404" />
<remove statusCode="500" />
<error statusCode="403" subStatusCode="-1" responseMode="ExecuteURL" path="Error403.aspx" />
<error statusCode="404" subStatusCode="-1" responseMode="ExecuteURL" path="Error404.aspx" />
<error statusCode="500" subStatusCode="-1" responseMode="ExecuteURL" path="Error500.aspx" />
</httpErrors>
添加:
到
部分。当我得到对象引用未设置为对象实例和空错误异常或除零异常错误时,它不会重定向到错误页面。
<httpErrors errorMode="Custom">
<error statusCode="500" path="/error/index" responseMode="Redirect" />
</httpErrors>