HttpContext.Current.Response 和 Page.Response 有什么区别?
我正在解决一组安全页面上的缓存问题,并意识到需要修改所有响应的标头。当我整理解决方案时,我想知道 HttpContext.Current.Response 和 Page.Response 之间的区别以及何时应在应用程序中使用每个对象。
谢谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Page.Response
只是当您处于 HTML 页面上下文中时到 HTTPContext 的映射。当您不在页面中时,
HttpContext.Current.Response
只是允许您访问当前上下文。允许您从响应请求的实际页面以外的位置访问上下文。至于什么时候使用每一个?如果您愿意,您“可以”在任何地方使用 HttpContext.Current.Response,但通常人们会在页面/用户控件上使用 Page.Response。
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.
对于初学者来说,Page.Response 意味着您有一个当前有效的 Page 对象,HttpContext 是静态的,可以随时调用 - 就像在 Global.asax 或 HttpModule/HttpHandler 中一样。
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.