Problem in Application_Error in Global.asax

Posted by mmtemporary on Stack Overflow See other posts from Stack Overflow or by mmtemporary
Published on 2010-05-06T10:31:09Z Indexed on 2010/05/06 10:38 UTC
Read the original article Hit count: 255

Filed under:

my problem is User.Identity.Name or Request.Url.AbsoluteUri in exception handling is empty when exception email to me.
this is Application_Code:

void Application_Error(object sender, EventArgs e) 
{
    Server.Transfer("~/errors/default.aspx");
}

and this is default.aspx code:

protected void Page_Load(object sender, EventArgs e)
{
    if (Server.GetLastError() == null)
        return;
    Exception ex = Server.GetLastError().GetBaseException();
    if (ex == null)
        return;

    string message = string.Format("User: ", User.Identity.Name);
    message += Environment.NewLine;
    message += string.Format("AbsoluteUri: ", Request.Url.AbsoluteUri);
    message += Environment.NewLine;
    message += string.Format("Form: ", Request.Form.ToString());
    message += Environment.NewLine;
    message += string.Format("QueryString: ", Request.QueryString.ToString());
    message += Environment.NewLine;

    HttpBrowserCapabilities browser = Request.Browser;
    string s = "Browser Capabilities:\n"
        + "Type = " + browser.Type + "\n"
        + "Name = " + browser.Browser + "\n"
        + "Version = " + browser.Version + "\n"
        + "Platform = " + browser.Platform + "\n"
        + "Is Crawler = " + browser.Crawler + "\n"
        + "Supports Cookies = " + browser.Cookies + "\n"
        + "Supports JavaScript = " + browser.EcmaScriptVersion.ToString() + "\n"
        + "\n";
    message += s;

    message += Environment.NewLine;
    message += ex.ToString();

    Exception lastException = (Exception)Application["LastException"];
    if (lastException == null || lastException.Message != ex.Message)
    {
        Application.Lock();
        Application["LastException"] = ex;
        Application.UnLock();
        SiteHelper.SendEmail(SiteHelper.AdministratorEMail, "Error!!!", message, false);
    }
    Server.ClearError();
}

but i receive email like this (this is header without full exception content):

User: 
AbsoluteUri: 
Form: 
QueryString: 
Browser Capabilities:
Type = IE8
Name = IE
Version = 8.0
Platform = WinXP
Is Crawler = False
Supports Cookies = True
Supports JavaScript = 1.2

why username and request url is emty?
this problem is exist when i replace transfer with redirect or i don't use both.
tanx

© Stack Overflow or respective owner

Related posts about ASP.NET