3

私のサイトはasp.netmvc2で実行されており、handleerror属性ではなく、エラートラップにelmahを使用しています。

'http:// localhost:8095 / Home / City / 1 / mtl / ko'のような存在しないページを参照すると、IISエラー404ページが表示されます。

web.configで、カスタムエラーを構成しました

global.asax application_errorにコードを設定しようとしましたが、そこにトラップされていません

IIS 404エラーページが表示されるのはなぜですか?

考えたところで、404エラーをログに記録したいのですが、これらをasp.net mvcのどこにトラップしますか?

ありがとう

4

1 に答える 1

0

これは古い質問であることは知っていますが、私は答えると思いました:

Elmah には、適用できるフィルタリングがあります: http://code.google.com/p/elmah/wiki/ErrorFiltering

エラー フィルタリングを有効にしたら、Gloabal.asax.cs を変更してエラーをフィルタリングする必要があります。

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();
        }
    }
}

しかし率直に言って、私は 404 エラーを含むすべてをログに記録するのが好きです。これにより、ユーザーがどのようにアクセスしようとしているか、必要に応じてサポートする新機能を発見しようとしているかをよりよく把握できます。

その他のリソース: 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/

于 2013-01-28T23:29:43.937 に答える