Server cannot set content type after HTTP headers have been sent

后端 未结 6 1086
离开以前
离开以前 2020-12-20 15:42

I get an error (Server cannot set content type after HTTP headers have been sent.) on the following code (ContentType line). What should I change?



        
相关标签:
6条回答
  • 2020-12-20 16:02

    Do you need to set the content type? This solution should not be overlooked, because you may find your code to work perfectly without the need to explicitly define the content type for the type of response you are sending. So removing the following line should make the error go away, and may very well do so without introducing new problems (of course you'll want to test this against your scenario):

    response.ContentType = "text/plain";

    0 讨论(0)
  • 2020-12-20 16:02

    This solution worked for me, add this line of code on the beginning of the method,

    Server.ClearError();
    
    0 讨论(0)
  • 2020-12-20 16:03

    I had a very similar issue to this on a webform. I solved this issue by adding the following code to my button in the code behind:

    ScriptManager.GetCurrent(this).RegisterPostBackControl(btnPrint);
    
    0 讨论(0)
  • 2020-12-20 16:09

    I had the same problem and the following solution solved the problem, run a response.ClearHeaders(); before run response.AddHeader(

    0 讨论(0)
  • 2020-12-20 16:22

    Have a look at HttpResponse.BufferOutput Property

    http://msdn.microsoft.com/en-us/library/33cy25ty%28v=vs.100%29.aspx

    0 讨论(0)
  • 2020-12-20 16:27

    Try setting response.BufferOutput = true;. Do this immediately after setting the response variable.

    0 讨论(0)
提交回复
热议问题