我在我的asp.net mvc 5 c#web应用程序中间歇性地获得此异常:
发送HTTP标头后,服务器无法附加标头.
它只是将图像上传到S3方法(Web Api控制器).
Global.asax中的presendrequestheaders
protected void Application_PreSendRequestHeaders(object sender, EventArgs e)
{
HttpApplication app = sender as HttpApplication;
if (app != null &&
app.Context != null)
{
app.Context.Response.Headers.Remove("Server");
}
}
Run Code Online (Sandbox Code Playgroud)
触发错误的方法:
[HttpPost]
[Route("UploadImageJSON")]
public IHttpActionResult UploadImageJSON(HttpRequestMessage request)
{
var httpRequest = HttpContext.Current.Request;
// Check if files are available
if (httpRequest.Files.Count != 1) return BadRequest();
var postedFile = httpRequest.Files[0];
var contentType = postedFile.ContentType;
if (!contentType.Contains("image"))
{
return StatusCode(HttpStatusCode.NotAcceptable);
}
var keyUploadFiles = Constants.UrlS3Amazon +
S3.UploadToS3WithStream(postedFile.InputStream, contentType);
return Json(JsonConvert.SerializeObject(keyUploadFiles));
}
Run Code Online (Sandbox Code Playgroud)
编辑:更多信息...我的Elastic BeanStalk托管了我的Web应用程序,负载均衡器,负载均衡器已安装SSL证书,负载均衡器和EC2实例之间的连接位于端口80.也许它可能是很有帮助.
Elmah日志:
System.Web.HttpException(0x80004005):在发送HTTP标头后,服务器无法附加标头.在Microsoft.Owin.Infrastructure.OwinHelpers的Microsoft.Owin.Host.SystemWeb.CallHeaders.AspNetResponseHeaders.Set(String key,String [] values)的System.Web.HttpHeaderCollection.SetHeader(String name,String value,Boolean replace)中. AppendHeaderUnmodified(IDictionary
2 headers, String key, String[] values) at Microsoft.Owin.ResponseCookieCollection.Append(String key, String value, CookieOptions options) at Microsoft.Owin.Security.Cookies.CookieAuthenticationHandler.<ApplyResponseGrantAsync>d__b.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Owin.Security.Infrastructure.AuthenticationHandler.<ApplyResponseCoreAsync>d__8.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Owin.Security.Infrastructure.AuthenticationHandler.<TeardownAsync>d__5.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Owin.Security.Infrastructure.AuthenticationMiddleware1.d__0.MoveNext()---从抛出异常的先前位置开始的堆栈跟踪结束---在System.Runtime.CompilerServices.TaskAwaiter的System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)处. Microsoft.AspNet.Identity.Owin.IdentityFactoryMiddleware中的HandleNonSuccessAndDebuggerNotification(任务任务)2.<Invoke>d__0.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.AspNet.Identity.Owin.IdentityFactoryMiddleware2.d__0.MoveNext()---从抛出异常的上一个位置开始的堆栈跟踪结束---在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(位于Microsoft.AspNet.Identity.Owin.IdentityFactoryMiddleware`2.d__0.MoveNext()的System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)的任务任务) - 从前一个位置开始的堆栈跟踪结束 xception被抛出---在Microsoft.Owin.Mapping.MapMiddleware.d__0.MoveNext()的System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)的System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)中 - - 从抛出异常的先前位置开始的堆栈跟踪结束---在System.Web上的Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.IntegratedPipelineContext.EndFinalult(IAsyncResult ar)处的System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()处. System.Web.HttpApplication.ExecuteStep中的HttpApplication.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()(IExecutionStep step,Boolean&completedSynchronously)
谢谢!!
| 归档时间: |
|
| 查看次数: |
2807 次 |
| 最近记录: |