I've added this in my web.config:
<customErrors mode="RemoteOnly" defaultRedirect="~/Site/Statics/Eroare.aspx">
<error statusCode="404" redirect="~/Site/Index.aspx" />
</customErrors>
Well, in Page_Load method o开发者_Go百科n Eroare.aspx page i try to print to my internal logs the error which caused this redirect but Server.GetLastError() is null...
Do you know why? Or any other solution to get the exception?
Thanks.
The key is to trigger the error in Global.asax file
protected void Application_Error(object sender, EventArgs e)
{
Exception objErr = Server.GetLastError().GetBaseException();
string err = "Error Caught in Application_Error event\n" +
"Error in: " + Request.Url.ToString() +
"\nError Message:" + objErr.Message.ToString() +
"\nStack Trace:" + objErr.StackTrace.ToString();
EventLog.WriteEntry("Sample_WebApp",err,EventLogEntryType.Error);
//Server.ClearError();
//additional actions...
}
More info: http://support.microsoft.com/kb/306355
精彩评论