RE: Remote Errors return NULL

From: Steven Cheng[MSFT] (v-schang_at_online.microsoft.com)
Date: 02/04/04


Date: Wed, 04 Feb 2004 02:54:33 GMT

Hi,

Thanks for posting in the community!
>From your description, you used a iframe page in one ASP.NET web
application to contain another page in a different web application.
However, when the inner page(contained in the iframe) run into error, the
error information didnt' display correctly. Also, you've tried use a custom
error page to display error info via the "Server.GetLastError" but still
with no result,yes?
If there is anything I misunderstood, please feel free to let me know.

1. As for the first problem, I agree to Felixwu's suggestion that try
change the <CustomError .. >'s "mode" attribute as "Off" so as to allow
displaying the detailed info of the exception.

2. As for using a custom error page to display the application error. There
are some points we need to take care.
We need to capture the Application_Error event of the Global class and
manually use "Server.Transfer" method to forward the response to the
"customerrorpage". Because by default, when an unhandled exception occur,
after the Appliction_Error event handler, the ASP.NET runtime will clear
the server error also the Session will be stoped and restart and new
Session(you may add some break points in the Global object's certain events
to have a check). So by default, in the custom error page, when we call
"Server.GetLastError()", we will get Nothing(null). So by using
"Server.Transfer" to manually redirect to custom error page in
Application_Error event, the server error info and the request's form
collections will remain so that we can retrieve and display it in custom
error page. For example, here is
what I use to store and retieve the server error from Application_Error
event to custom error page 's Page_Load event:
##in Application_Error:
protected void Application_Error(Object sender, EventArgs e)
{
        Exception ex = Server.GetLastError();
                        
        HttpContext.Current.Response.Clear();
        Server.Transfer("CustomErrorPage.aspx");
}

##in CustomErrorPage.aspx 's code behind
public class CustomErrorPage : System.Web.UI.Page
{
        protected System.Web.UI.WebControls.Label lblCallStack;
        protected System.Web.UI.WebControls.Label lblSource;
        protected System.Web.UI.WebControls.Label lblMessage;
        
        private void Page_Load(object sender, System.EventArgs e)
        {
                Exception ex = Server.GetLastError();
                lblMessage.Text = ex.Message;
                lblCallStack.Text = ex.StackTrace;
                lblSource.Text = ex.Source;
        }
...................
}

In addition, here is a tech article on providing custom error handing and
reporting:

#Rich Custom Error Handling with ASP.NET
http://msdn.microsoft.com/library/en-us/dnaspp/html/customerrors.asp?frame=t
rue

Please check out the above suggestions. If there're anything unclear,
please feel free to post here.

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.)



Relevant Pages

  • RE: Cannot display Custom Error Page
    ... > the error page from a remote system. ... >> does not display this page whenever an unhandled exception is thrown. ... >> to the filename of the custom error page, ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Display the error on a custome error page
    ... Do you try to save only the string Ex.Message or the full exception object ... Do you use GetLastError()? ... > I'm trying to display Ex.Message on a custom error page. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Custom 404 errors in IIS 6
    ... Take a look at the iis log file. ... "NH Web Group" wrote in message ... > display the edited version of the 404b.html page but this one site will ... > I have tried to set the Custom Error to “default” and restart the website ...
    (microsoft.public.inetserver.iis)
  • Re: Custom "No Image Found" instead of "X"
    ... Since the browser decides the image to display for an "image not found", ... only way you can control what browsers display is for a 404 custom error of ...
    (microsoft.public.inetserver.iis)
  • RE: DefaultRedirect Problem
    ... Thanks for posting in the community! ... you used a custom error page ... so as to use the certain aspx page as the default error page. ... public class CustomErrorPage: System.Web.UI.Page ...
    (microsoft.public.dotnet.framework.aspnet)