Setting Alternative Session Expiration Times in asp.net
I want a specific 开发者_JS百科session variable (in my case Session["level"]) to expire either on the normal 20 min. timer or at 19:30 every day. Because I change a value in my database everyday at 19:30 and I want this session variable to be related to that value. Is this possible? Thanks in advance.
You can try something like this:
if (DateTime.Now.TimeOfDay > TimeSpan.Parse("19:30"))
{
Session["level"] = null;
}
If you're using masterpages or all of your aspx pags are extending a base page, put it inside the page_load.
You could also stick code in the method to grab the updated Session["level"] value and assign it, instead of setting it to null.
精彩评论