problem with cache

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?
 
G

Gregory A. Beamer

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! |
************************************************
 
J

Jeff

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top