user1787578
user1787578

Reputation: 63

Different session time out for different users

Is it possible to have different session time outs for different users? I need to have 180 mins session for admin and 20 min for non-admin users. Currently it is single session timeout for all the users. we are using a web.config key

Any help would be appriciated.

Upvotes: 6

Views: 4930

Answers (1)

Learning
Learning

Reputation: 20001

Setting Session.Timeout property by code will set the timeout on a per user basis.

You can manually set Session.Timeout = 20; or Session.Timeout = 180; based on the user type when they log in.

This code should work for you:

protected void SetSessionTime(string userType)
{
    if (UserType == "admin")
    {
        Session.Timeout = 180;
    }
    else
    {
        Session.Timeout = 20;
    }
}

You can call SetSessionTime() after user successfully logs in.

Upvotes: 6

Related Questions