ASP.NET JQuery AJAX POST returns data but within a 401 response

…衆ロ難τιáo~ 提交于 2019-12-06 11:59:45

Move your Response.Write call before your call to Flush.

    this.Context.Response.Write(response);
    this.Context.Response.Flush();

UPDATE: You can also try removing the ContentType setter, since you're already stating that your response type is JSON.

Can you try stripping it back from:

this.Context.Response.Clear();
        this.Context.Response.ContentType = "application/json";
        this.Context.Response.Flush();
        this.Context.Response.Write(response);

to just:

this.Context.Response.Write(response);

or even

this.Context.Response.BufferOutput = true;
this.Context.Response.Write(response);
this.Context.Response.End();

edit

It sounds like you could be experiencing this behaviour:

  1. you write something to repsonse
  2. you flush
  3. your code triggers an error, asp.net tries to rewrite the headers, which is disallowed because the call to Flush() already wrote the headers

stick a try catch in there and see if anything throws.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!