我有这个配置工作,并正确重定向以下错误
<httpErrors errorMode="Custom" existingResponse="Replace" defaultResponseMode="ExecuteURL" > <remove statusCode="403" /> <remove statusCode="404" /> <remove statusCode="500" /> <error statusCode="403" responseMode="ExecuteURL" path="/Error/AccessDenied" /> <error statusCode="404" responseMode="ExecuteURL" path="/Error/PageNotFound" /> <error statusCode="500" responseMode="ExecuteURL" path="/Error/ApplicationError" /> </httpErrors>
<httpErrors errorMode="Custom" existingResponse="Replace" defaultResponseMode="ExecuteURL" defaultPath="/Error/ApplicationError">
服务器抛出web.config错误
HTTP Error 500.19 - Internal Server Error The requested page cannot be accessed because the related configuration data for the page is invalid. Module CustomErrorModule
现在这与documentation on msdn直接矛盾
任何帮助将不胜感激!!
解决方法
使用defaultPath属性可防止在错误节点中使用path属性.所以下面的配置会起作用(但是当然它会为这里定义的所有HTTP错误显示相同的错误页面):
<httpErrors errorMode="Custom" existingResponse="Replace" defaultResponseMode="ExecuteURL" defaultPath="/Error/ApplicationError"> <remove statusCode="403" /> <remove statusCode="404" /> <remove statusCode="500" /> <error statusCode="403" responseMode="ExecuteURL" /> <error statusCode="404" responseMode="ExecuteURL" /> <error statusCode="500" responseMode="ExecuteURL" /> </httpErrors>
相关文档:https://msdn.microsoft.com/en-us/library/ms690576(v=vs.90).aspx