problem with cache

  • Thread starter Thread starter Jeff
  • Start date Start date
J

Jeff

hi

asp.net 3.5

I added this markup to default.aspx:
<%@ OutputCache Duration="3600" VaryByParam="none" %>

Then when I try to login and click the submit button nothing happens. I'm
not logged in.
Now when I click on the other pages on the site (e.g navigate to other pages
than default.aspx), on those pages
I'm logged in. Going back to default.aspx and I'm loggout...

Think this has something to do with pages was cached for an hour and asp.net
is just showing the cached version. I hope there are some parameters or
somehting I need to specify to solve it..

any ideas?
 
Jeff said:
hi

asp.net 3.5

I added this markup to default.aspx:
<%@ OutputCache Duration="3600" VaryByParam="none" %>

Then when I try to login and click the submit button nothing happens. I'm
not logged in.
Now when I click on the other pages on the site (e.g navigate to other
pages than default.aspx), on those pages
I'm logged in. Going back to default.aspx and I'm loggout...

Think this has something to do with pages was cached for an hour and
asp.net is just showing the cached version. I hope there are some
parameters or somehting I need to specify to solve it..

Don't cache a page with vary by none if it has different states. You can
vary it by custom and set it for role or user or something, but don't vary
by nothing.

--
Peace and Grace,
Greg

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

************************************************
| Think outside the box! |
************************************************
 
I think I've managed to solve it using varybycustom.

Here is a method I had to add to Global.asax:
public override string GetVaryByCustomString(HttpContext context, string
custom)
{
// This check ensures that if a user's authentication state changes,
// the page is not cached.
if (custom == "Login")
return User.Identity.IsAuthenticated.ToString();

return base.GetVaryByCustomString(context, custom);
}

in default.aspx I updated the tag to:
<%@ OutputCache Duration="3600" VaryByParam="none" VaryByCustom="Login" %>

It seams to be working ok, haven't tested it so much but the problem I had
is gone.
 
Back
Top