HttpContext.Current.Response 和 Page.Response 有什么区别?

发布于 2024-08-09 19:41:28 字数 136 浏览 4 评论 0原文

我正在解决一组安全页面上的缓存问题,并意识到需要修改所有响应的标头。当我整理解决方案时,我想知道 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

も星光 2024-08-16 19:41:28

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.

鹿港巷口少年归 2024-08-16 19:41:28

对于初学者来说,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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文