我如何在MVC应用程序的当前用户? [英] How do I get the current user in an MVC Application?

查看:104
本文介绍了我如何在MVC应用程序的当前用户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:

  如何获取当前用户在Asp.Net MVC

我已经尝试了一堆不同的东西,我知道我当我用Web表单之前已经做了,但我似乎无法弄清楚如何做到这一点的MVC。

I've tried a bunch of different things, I know I've done it before when I used Webforms, but I can't seem to figure out how to do it in MVC.

会员不起作用
用户给了我一个IPrincipal什么User.Identity使我有同样类型的变量...

Membership doesn't work User gives me an IPrincipal or something User.Identity gives me the same type of variable...

任何人都知道吗?是否有任何GetCurrentUser()方法或类似的东西?

Anyone know? Is there any GetCurrentUser() method or something similar?

推荐答案

在这里看到迈赫达德的回答是:<一href=\"http://stackoverflow.com/questions/1045593/system-web-ui-page-wont-let-me-access-currentuser-or-user-identity-from-a-contro/1045607#1045607\">http://stackoverflow.com/questions/1045593/system-web-ui-page-wont-let-me-access-currentuser-or-user-identity-from-a-contro/1045607#1045607

See Mehrdad's answer here: http://stackoverflow.com/questions/1045593/system-web-ui-page-wont-let-me-access-currentuser-or-user-identity-from-a-contro/1045607#1045607

他解释说,你可以使用

User.Identity // in the controller
HttpContext.User.Identity // in the controller
System.Web.HttpContext.Current.User.Identity // anywhere

这篇关于我如何在MVC应用程序的当前用户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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