如何获得当前用户,以及如何使用User类的MVC5
答案:1 悬赏:0
解决时间 2021-02-17 13:04
- 提问者网友:戎马万世
- 2021-02-16 22:00
如何获得当前用户,以及如何使用User类的MVC5
最佳答案
- 二级知识专家网友:轻熟杀无赦
- 2021-02-16 22:45
在这里面我重写OnAuthentication并设置filterContext.HttpContext.User to null这是最好的
public abstract class ApplicationController : Controller
{
...
protected override void OnAuthentication(AuthenticationContext filterContext)
{
base.OnAuthentication(filterContext);
if ( ... )
{
// You may find that modifying the
// filterContext.HttpContext.User
// here works as desired.
// In my case I just set it to null
filterContext.HttpContext.User = null;
}
}
...
}
public abstract class ApplicationController : Controller
{
...
protected override void OnAuthentication(AuthenticationContext filterContext)
{
base.OnAuthentication(filterContext);
if ( ... )
{
// You may find that modifying the
// filterContext.HttpContext.User
// here works as desired.
// In my case I just set it to null
filterContext.HttpContext.User = null;
}
}
...
}
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯