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

前端之家收集整理的这篇文章主要介绍了asp.net – Response.End()和Response.Flush()之间的差异前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有这样的代码
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.

猜你在找的asp.Net相关文章