Prevent page from being cached on client, but do cache images.

  • Thread starter Thread starter moondaddy
  • Start date Start date
M

moondaddy

I'm using vb.net 1.1 and have a bit of a catch 22 situation. I have a login
and logout button and code. I'm using frames (header, left side menu, and
main where the various pages load). When the user clicks the logout button
in the left side frame this jscript runs:

parent.main.frameElement.src="Logout.aspx"

logout.aspx is a blank page with the code below in the page_load event which
logs the user out and redirects the home page back to the main frame.

FormsAuthentication.SignOut()
UrlHelper.RedirectWithMessage("home.aspx", PageMessage.Logged_Out)

The home.aspx page_load event I have code that needs to execute some of
which is RegisterStartupScript to write and execute code on the client which
changes the general state depending on if the user is logged in or not.

My problem is that the home.aspx page_load event doesn't fire because the
browser is caching an instance of it already. I know that if I insert the
following line of code the home page will never be cached and this code will
always run.

Response.Cache.SetCacheability(HttpCacheability.NoCache)

That's good, but I have large graphics on the home page that I don't want to
have to reload everytime the user navigates back to the home page. I see 2
possible solutions (in theory) but don't know if they can actually work.

1) run a line of code after the one above that tells the images to be cached
even when the page's HttpCacheability is set to NoCache

2)Wrap the images in user controls where I could tell them to be cached
while the control's parent (home.aspx) is not being cached.

What should I do?

Thanks!
 
Hi Moondaddy,

From your description, you'd like to set some aspx page uncached on the
clientside. However, since there're may images displayed in these pages ,
so you'd like to still remain these images cached on clientside yes?

As for this problem, I think you can still use the
Response.Cache.SetCacheability(HttpCacheability.NoCache)
to set the page's cache ability, this will cause the certain url of the
page be cached, when the certain page url be visted again, browser
retrieved page from serverside rather than local temp folder. However, as
for the Images, the browser(IE) will be default cache it in the temporay
folder no matter its container page is cached or not. We can make a simple
test, put some images in the page which has set cache ability as NoCache,
then visist it from a client machine's browser. If that, we lookup the
internet temporary folder, we can still found the cached images in the
folder.
Also, there is no such serverside code that can specify caching certain
images. And the User Control is some thing like a #include file, so its
still part of the page, no any particular difference on cache. How do you
think?


Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
 
Back
Top