0
我的問題是User.Identity.Name或Request.Url.AbsoluteUri在異常處理時是空的,當我發送異常郵件給我時。
這是Application_Code:Global.asax中Application_Error中的問題
void Application_Error(object sender, EventArgs e)
{
Server.Transfer("~/errors/default.aspx");
}
,這是Default.aspx的代碼:
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;
,但我收到的電子郵件這樣的(這是不完整的例外內容頭):
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
爲什麼用戶名和請求的URL是emty?
當我用重定向替換傳輸或者我不同時使用這個問題時存在。
坦
也很好的調用了stringbuilder,AppendFormat方法將是理想的 – Pharabus 2010-05-06 11:46:30