tags:

views:

17

answers:

0

We're migrating our aspnet app from IIS 6, aspnet 2.0 tp IIS 7.0 3.5 framework.

We're having an issue with our error handling. In our Globax.asax.cs Application_Error event, we capture errors and log them and then use Server.TransferRequest (formerly Server.Transfer) to our ErrorPage.aspx.

In the ErrorPage.aspx, we have some code in our page, to see what type of error it is and display a custom error. Something like this:

protected void Page_Load(object sender, EventArgs e)
    {        
        Exception ex = null;        
        LogLevel level = LogLevel.Info;

        string errMessage = string.Empty;

        if (Context.Error != null)
        {
            if (Context.Error.InnerException == null)
            {
                ex = Context.Error;
            }
            else
            {
                ex = Context.Error.InnerException;
            }
        }

        if (ex == null)
        {
            errMessage = "No error was detected; please try logging in again.  If this problem persists contact the system administrator";
        }
        else if (ex is HttpException)
        {            
            switch (((HttpException)ex).GetHttpCode())
            {
                case 403:
                    {
                        errMessage = "You are not allowed to view this page.";
                        break;
                    }
//blah blah 

What's happening though is that the Context.Error is always returning null. I can't figure out why. I thought from this article http://forums.iis.net/t/1146511.aspx it will rerun the entire request and thus I will have access to the Context.Error object.

Any ideas or help would be appreciated.

Thanks, Bill N