Problem in Application_Error in Global.asax
- by mmtemporary
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