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.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 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.
Method 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.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0