ELMAH不显示错误代码行号(服务器无法在发送HTTP标头后设置状态)

时间:2016-06-22 16:06:46

标签: asp.net-mvc elmah

我收到了许多ELMAH生成的电子邮件。它们只显示堆栈跟踪.Net Framework代码,但它们都不是我的代码。因此我不知道bug在哪里。如何配置ELMAH以显示发生错误的代码行? web.config有

<compilation defaultLanguage="c#" targetFramework="4.5.2">

以下是ELMAH生成的电子邮件

System.Web.HttpException: Server cannot set status after HTTP headers have been sent.
Generated: Tue, 21 Jun 2016 23:23:03 GMT

System.Web.HttpException (0x80004005): Server cannot set status after HTTP headers have been sent.
   at System.Web.HttpResponse.set_StatusCode(Int32 value)
   at System.Web.Mvc.HandleErrorAttribute.OnException(ExceptionContext filterContext)
   at System.Web.Mvc.ControllerActionInvoker.InvokeExceptionFilters(ControllerContext controllerContext, IList`1 filters, Exception exception)
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult)
   at System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult)
   at System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult)
   at System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult)
   at System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult)
   at System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult)
   at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

Server Variables 
Name    Value
ALL_HTTP    removed
ALL_RAW removed
APPL_MD_PATH    /LM/W3SVC/2/ROOT/CMT
APPL_PHYSICAL_PATH  D:\webs\mydomain\CMT\
AUTH_TYPE   NTLM
AUTH_USER   domain\username
AUTH_PASSWORD   *****
LOGON_USER  domain\username
REMOTE_USER domain\username
CERT_COOKIE  
CERT_FLAGS   
CERT_ISSUER  
CERT_KEYSIZE    256
CERT_SECRETKEYSIZE  2048
CERT_SERIALNUMBER    
CERT_SERVER_ISSUER  removed
CERT_SERVER_SUBJECT removed
CERT_SUBJECT     
CONTENT_LENGTH  0
CONTENT_TYPE     
GATEWAY_INTERFACE   CGI/1.1
HTTPS   on
HTTPS_KEYSIZE   256
HTTPS_SECRETKEYSIZE 2048
HTTPS_SERVER_ISSUER removed
HTTPS_SERVER_SUBJECT    removed
INSTANCE_ID 2
INSTANCE_META_PATH  /LM/W3SVC/2
LOCAL_ADDR  removed
PATH_INFO   /cmt/
PATH_TRANSLATED D:\webs\mydomain\CMT\
QUERY_STRING     
REMOTE_ADDR removed
REMOTE_HOST removed
REMOTE_PORT 54590
REQUEST_METHOD  GET
SCRIPT_NAME /cmt/
SERVER_NAME removed
SERVER_PORT 443
SERVER_PORT_SECURE  1
SERVER_PROTOCOL HTTP/1.1
SERVER_SOFTWARE Microsoft-IIS/8.5
URL /cmt/
HTTP_CONNECTION Keep-Alive
HTTP_ACCEPT */*
HTTP_ACCEPT_ENCODING    gzip, deflate, peerdist
HTTP_ACCEPT_LANGUAGE    en-US 
HTTP_AUTHORIZATION  removed
NTLM HTTP_COOKIE    removed
HTTP_HOST   removed
HTTP_USER_AGENT Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/7.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; InfoPath.3; .NET4.0C; .NET4.0E)
HTTP_DNT    1
HTTP_X_P2P_PEERDIST Version=1.0
Powered by ELMAH, version 1.2.14706.955. Copyright (c) 2004, Atif Aziz. All rights reserved. Licensed under Apache License, Version 2.0. 

1 个答案:

答案 0 :(得分:0)

当我们看不到您的控制器处理失败的请求时,确定确切的问题有点困难。我的看法是,您的操作包含一些异步代码,它们在从请求返回后实际运行。

你可以通过在try-catch中包含你的代码并使用ELMAH中的ErrorSignal类来记录动作中抛出的实际错误。但同样,为我们提供更多代码,可以更容易提供帮助。