加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net – Response.End()和Response.Flush()之间的差异

发布时间:2020-12-15 23:38:06 所属栏目:asp.Net 来源:网络整理
导读:我有这样的代码: context.HttpContext.Response.Clear(); context.HttpContext.Response.Write(htmlString); context.HttpContext.Response.End(); 但是,当页面加载时,我已经没有关闭html标签.当我用Response.Flush()替换Response.End()它工作正常. Respons
我有这样的代码:
context.HttpContext.Response.Clear();
            context.HttpContext.Response.Write(htmlString);              
            context.HttpContext.Response.End();

但是,当页面加载时,我已经没有关闭html标签.当我用Response.Flush()替换Response.End()它工作正常.
Response.End()和Response.Flush()之间有什么区别?

解决方法

Response.Flush

Forces all currently buffered output to be sent to the client. The
Flush method can be called multiple times during request processing.

到Response.End

Sends all currently buffered output to the client,stops execution of
the page,and raises the EndRequest event.

如果在Response.Write之后没有对页面进行任何处理,并且希望停止处理页面,则应该尝试使用此代码.

context.HttpContext.Response.Clear();
    context.HttpContext.Response.Write(htmlString);              
    context.HttpContext.Response.Flush(); // send all buffered output to client 
    context.HttpContext.Response.End(); // response.end would work fine now.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读