2010-05-06 75 views
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?
当我用重定向替换传输或者我不同时使用这个问题时存在。

回答

2

你不是已经在正确的方式

试试这个设置的String.Format。

string.Format("AbsoluteUri: {0}", Request.Url.AbsoluteUri); 

我怎么建议使用StringBuilder这个代码。

+0

也很好的调用了stringbuilder,AppendFormat方法将是理想的 – Pharabus 2010-05-06 11:46:30

相关问题