RE: DefaultRedirect Problem
From: Steven Cheng[MSFT] (v-schang_at_online.microsoft.com)
Date: 02/03/04
- Next message: hansiman: "Reload DataGrid on DropDownList onChangeIndex"
- Previous message: Mike: "Re: Problem Debugging"
- In reply to: Gary: "DefaultRedirect Problem"
- Next in thread: Steven Cheng[MSFT]: "RE: DefaultRedirect Problem"
- Reply: Steven Cheng[MSFT]: "RE: DefaultRedirect Problem"
- Reply: Gary: "Re: DefaultRedirect Problem"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 03 Feb 2004 07:48:07 GMT
Hi Gary,
Thanks for posting in the community!
>From your description, you used a custom error page( a asp.net aspx page)
and set in the web.config via the
<customErrors defaultRedirect="CustomErrorPage.aspx" mode="On">
</customErrors>
so as to use the certain aspx page as the default error page. However, you
encoutered runtime error when execute and redirect to the error page, yes?
If there is anything I misunderstood, please feel free to let me know.
Based on my research, this problem is due to the Server's LastError has
already been cleared before the CustomError Page is loaded. For example, if
you add the below code in your custom error aspx page:
if(!IsPostBack)
{
Exception exp = Server.GetLastError();
if(exp != null)
{
lblMessage.Text = exp.Message;
}
}
we can find that the "exp" is always an empty object, so the server error
has been cleared up. So if we use Server.GetLastError().Message to retrieve
info from it, we'll get exception.
And One way to keep the server error information so as to be used in the
Custom error page is to pre-store the error's information before the custom
error page is loaded. For example, in the "Application_Error" event of the
Global class:
protected void Application_Error(Object sender, EventArgs e)
{
Session["Last_Error_Info"] = Server.GetLastError().Message;
}
Then, in the custom error page, we can retrieve the info from the Session
so as to output it on the custom error page, such as:
public class CustomErrorPage : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label lblMessage;
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
string msg = (string)Session["Last_Error_Info"];
if(msg != null)
{
lblMessage.Text = msg;
}
}
}
.........................
}
Please check out my suggestion to see whether it helps you. If you feel
anything unclear or have any questions, please always feel free to let me
know.
Regards,
Steven Cheng
Microsoft Online Support
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
- Next message: hansiman: "Reload DataGrid on DropDownList onChangeIndex"
- Previous message: Mike: "Re: Problem Debugging"
- In reply to: Gary: "DefaultRedirect Problem"
- Next in thread: Steven Cheng[MSFT]: "RE: DefaultRedirect Problem"
- Reply: Steven Cheng[MSFT]: "RE: DefaultRedirect Problem"
- Reply: Gary: "Re: DefaultRedirect Problem"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|