asp.net not displaying a custom 404 page as configured

╄→гoц情女王★ 提交于 2019-12-10 14:53:31

问题


in my web config I have:

<customErrors mode="On">
  <error statusCode="404" redirect="~/error/404.aspx" />
</customErrors>

http://localhost/meh <-- standard 404 is shown

http://localhost/meh.aspx <-- custom 404 is shown

http://localhost/error/404.aspx <-- the custom error page I want shown for all 404 errors

How do I have to setup my web.config to send all 404 to my custom error?

Thanks


回答1:


You have to configure this in IIS. By default, only specific files will get routed through the ASP.NET framework... otherwise IIS will handle it.




回答2:


Use the Application_Error event handler in the global.asax file to redirect the user to ~/error/meh.aspx

in global.asax

 protected void Application_Error(object sender, EventArgs e)
 {
      Response.Redirect("~/error/404.aspx");

 }

In your web.config, also add

  <customErrors mode="On" defaultRedirect="/error/404.aspx" />


来源:https://stackoverflow.com/questions/5185799/asp-net-not-displaying-a-custom-404-page-as-configured

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!