Skip to main content
 首页 » 编程设计

c#之捕获所有 StatusCodes

2024年08月12日52youxin

有没有一种简单的方法可以在 Web 配置中捕获多个/所有 http 状态代码? 目前我有

<customErrors mode="Off"> 
  <error statusCode="500" redirect="~/Account/Error"/> 
  <error statusCode="404" redirect="~/Account/NotFound"/> 
</customErrors> 

但是假设我想捕获 501、502、503 等等,我没有办法做一个范围或处理所有状态代码吗?如果可能的话,我宁愿不要对每个错误都进行硬编码

请您参考如下方法:

只需将 defaultRedirect 属性添加到 customErrors 标记即可。 搜索以下示例: http://tech.trailmax.info/2013/08/error-handling-in-mvc-and-nice-error-pages/