2015-07-08 3 views
17

मैं अपने asp.net MVC के 5 सी # वेब अनुप्रयोग में रहकर इस अपवाद प्राप्त भेज दिया गया है के बाद:सर्वर हेडर संलग्न नहीं कर सकता HTTP हेडर फ़ाइलों को अपलोड करने

Server cannot append header after HTTP headers have been sent.

यह सिर्फ S3 विधि करने के लिए छवियों को अपलोड होता है (वेब ​​एपीआई नियंत्रक)।

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"); 
      } 
     } 

विधि है कि त्रुटि उत्पन्न:

[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)); 


    } 

संपादित करें: अधिक जानकारी ... मैं अपने वेब एप्लिकेशन लचीला बीनस्टॉक में साथ की मेजबानी की है लोड बैलेंसर, लोड बैलेंसर ने एसएसएल प्रमाणपत्र स्थापित किया है, और लोड बैलेंसर और ईसी 2 उदाहरणों के बीच कनेक्शन पोर्ट्स 80 में हैं। शायद यह सहायक हो सकता है।

Elmah लॉग:

System.Web.HttpException (0x80004005): Server cannot append header after HTTP headers have been sent. at System.Web.HttpHeaderCollection.SetHeader(String name, String value, Boolean replace) at Microsoft.Owin.Host.SystemWeb.CallHeaders.AspNetResponseHeaders.Set(String key, String[] values) at Microsoft.Owin.Infrastructure.OwinHelpers.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.AuthenticationMiddleware 1.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.IdentityFactoryMiddleware 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.IdentityFactoryMiddleware 2.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.IdentityFactoryMiddleware`2.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.Owin.Mapping.MapMiddleware.d__0.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.IntegratedPipelineContext.EndFinalWork(IAsyncResult ar) at System.Web.HttpApplication.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

धन्यवाद !!

+0

प्रत्येक बार जब आप अपनी विधि के साथ एक छवि अपलोड करते हैं तो यह पहुंचा? क्योंकि आपने शुरुआत में कहा था कि यह एक अड़चन मुद्दा है ... – D4rkTiger

+0

क्या आपके पास कोई HTTP मॉड्यूल है जो प्रतिक्रिया गुज़र रही है? – hivie7510

+0

मुझे पता है कि – chemitaxis

उत्तर

1

क्या आपने ऐप को हटाने के साथ प्रयास किया है। कॉन्टैक्ट.रेस्पॉन्स.हेडर। रिमूव ("सर्वर"); मुझे लगता है कि यह मुद्दा है?

संबंधित मुद्दे