我们可以个性化 ASP.NET MVC 5 中角色的会话超时吗 [英] Can we personalize Session Timeout for Roles in ASP.NET MVC 5

查看:18
本文介绍了我们可以个性化 ASP.NET MVC 5 中角色的会话超时吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个想法是为Session Timeout设置不同的值ASP.NET MVC 5 和 ASP.NET Identity 中的不同用户角色.

The idea is to set different values of Session Timeout for different User Roles in ASP.NET MVC 5 and ASP.NET Identity.

可以吗?

推荐答案

根据他们的角色,您可以设置超时,即

Based on their role you could set the timeout, i.e.

HttpContext.Current.Session.Timeout = 20;

根据您之前的问题,您希望动态执行此操作.您可以在会话中存储和更新时间,并为基本控制器的 OnActionExecuting 上的每个角色设置.

Going by your previous question you want to do this dynamically. You could store and update the times themselves in session and set for each role on OnActionExecuting of a base controller.

    if (User.IsInRole("Admin"))
    {
        filterContext.HttpContext.Session.Timeout = 
(int)filterContext.HttpContext.Session["AdminTimeoutThatYouSetSomewhereElseGlobally"];
    }

这篇关于我们可以个性化 ASP.NET MVC 5 中角色的会话超时吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆