如何显示自定义的404页的ASP.NET没有重定向?自定义、重定向、ASP、NET

2023-09-04 05:18:27 作者:小巷里的女流氓

当一个请求是在ASP.NET 404在IIS 7我要显示自定义错误页。在地址栏的网址不应该改变,所以没有重定向。我怎样才能做到这一点?

When a request is 404 in ASP.NET on IIS 7 i want a custom error page to be displayed. The URL in the address bar should not change, so no redirect. How can i do this?

推荐答案

在应用程序的OnError事件可以为HttpExceptions测试与404状态code,然后做一个Server.Transfer的到自定义404页,代替的Response.Redirect。看一看 HTTP://blog.dmbcllc。 COM / 2009/03/02 / ASPNET-的Application_Error检测-404 /

In your application's OnError event you can test for HttpExceptions with a status code of 404, and then do a Server.Transfer to your custom 404 page, instead of a Response.Redirect. Have a look at http://blog.dmbcllc.com/2009/03/02/aspnet-application_error-detecting-404s/

 
精彩推荐
图片推荐