What is the difference between HttpContext.Current.Response and Page.Response?

谁说胖子不能爱 提交于 2020-01-23 11:07:34

问题


I'm troubleshooting a caching issue on a set of secured pages and have realized that the Header needs to be modified for all Responses. As I put together a solution, I want to know the difference between HttpContext.Current.Response and Page.Response and when each object should be used in an app.

Thanks.


回答1:


Page.Response is simply a mapping to the HTTPContext when you are within the context of an HTML page.

HttpContext.Current.Response simply allows you to get to the current context, when you are not in a page. ALlowing you to access the context from locations other than the actual page responding to the request.

As for when to use each? Well you "Can" use HttpContext.Current.Response everywhere if you want, but typically people will use Page.Response when on a page/usercontrol.




回答2:


Well for starters Page.Response implies that you have a current, valid Page object, HttpContext is static and can be called at any time - like in your Global.asax or and HttpModule/HttpHandler.



来源:https://stackoverflow.com/questions/1676503/what-is-the-difference-between-httpcontext-current-response-and-page-response

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