开发者

Can I handle all errors through ASP.Net?

开发者 https://www.devze.com 2023-02-11 22:29 出处:网络
I am trying to create a 404 handling page but I am now stuck with the page only working for .aspx files, which isn\'t really what I need.

I am trying to create a 404 handling page but I am now stuck with the page only working for .aspx files, which isn't really what I need.

I am running on IIS6. The site has a wildcard mapping, for extensionless URLs. All requests go through Application_BeginRequest in Global.asax but not all errors go through Application_Error.

Is there a way where I开发者_Go百科 can get the Application_Error to raise for non .aspx files?

This is the code inside the Application_Error

HttpException serverError = (HttpException)Server.GetLastError();

if (serverError != null) {
    int errorCode = serverError.GetHttpCode();
    if (errorCode == 404) {
        Server.ClearError();
        Server.Transfer("/errorPage.aspx");
    }
}


The only way I've successfully handled this with IIS 6 is to add a specific handler for 404 in IIS custom errors that points to one of your .aspx or .ashx files (i.e. point it to your errorPage.aspx).

0

精彩评论

暂无评论...
验证码 换一张
取 消