温馨提示×

customerrors支持自定义状态码吗

小樊
81
2024-07-03 11:06:11
栏目: 编程语言

是的,CustomErrors 元素支持自定义状态码。您可以在 web.config 文件中配置自定义错误页面,并为每个错误页面指定相应的 HTTP 状态码。例如:

<customErrors mode="On" defaultRedirect="ErrorPage.aspx">
  <error statusCode="404" redirect="NotFoundPage.aspx" />
  <error statusCode="500" redirect="ServerErrorPage.aspx" />
</customErrors>

在上面的示例中,当发生 404 错误时,用户将被重定向到 NotFoundPage.aspx 页面,并且响应状态码将为 404。同样,当发生 500 错误时,用户将被重定向到 ServerErrorPage.aspx 页面,并且响应状态码将为 500。您可以根据需要配置更多的状态码和对应的错误页面。

0