猿问

ErrorPage无法捕获Exception

普通頁面:

protected void Page_Load(object sender, EventArgs e)
    {
        throw new Exception("hello");
    }

ErrorPage:

 protected void Page_Error(object sender, EventArgs e)
    {
        Response.Write(Server.GetLastError().GetBaseException().Message);
        Server.ClearError();
    }

Web.Config

<customErrors mode="On" defaultRedirect="ErrorPage.aspx"/>


 問題:

ErrorPage.aspx的Server.GetLastError()总是为空,如何才能获取出错页面的Exception Message呢?


DIEA
浏览 940回答 1
1回答
随时随地看视频慕课网APP
我要回答