开发者

asp.net mvc 2 customErrors iis 7.5 not working

开发者 https://www.devze.com 2023-01-31 03:27 出处:网络
My site is running on asp.net mvc2 and I\'m using elmah for error trapping, not the handleerror attibute

My site is running on asp.net mvc2 and I'm using elmah for error trapping, not the handleerror attibute

if I browse to a non existing page like 'http://localhost:8095/Home/City/1/mtl/ko' I get t开发者_Python百科he IIS error 404 page

in web.config i have configured my custom errors

I even tried to set code in global.asax application_error and it's not being trapped there

why am I getting the IIS 404 error page ?

Now that I think about it I would like to log the 404 errors, where would I trap these in asp.net mvc ?

Thanks


I know this is an old question but thought I answer:

Elmah has filtering that you can apply: http://code.google.com/p/elmah/wiki/ErrorFiltering

Once you enabled the error filtering you need to modify the Gloabal.asax.cs to filter the error:

public static void RegisterRoutes(RouteCollection routes)
{               
    routes.IgnoreRoute("elmah.axd"); //Add this line to the register routes.
}

//ELMAH Filtering
protected void ErrorLog_Filtering(object sender, ExceptionFilterEventArgs e)
{
    FilterError404(e);
}

protected void ErrorMail_Filtering(object sender, ExceptionFilterEventArgs e)
{
    FilterError404(e);
}

//Dimiss 404 errors for ELMAH
private void FilterError404(ExceptionFilterEventArgs e)
{
    if (e.Exception.GetBaseException() is HttpException)
    {
        HttpException ex = (HttpException)e.Exception.GetBaseException();

        if (ex.GetHttpCode() == 404)
        {
            e.Dismiss();
        }
    }
}

But frankly I like to log everything including the 404 errors. This gives me a better view of how users are trying to get in or discover new features to support if need.

Other resources: http://joel.net/logging-errors-with-elmah-in-asp.net-mvc-3--part-3--filtering http://ivanz.com/2011/05/08/asp-net-mvc-magical-error-logging-with-elmah/

0

精彩评论

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