Different session time out for different users

2019-04-08 04:52发布

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.

1条回答
Summer. ? 凉城
2楼-- · 2019-04-08 05:09

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.

查看更多
登录 后发表回答