如何在ASP.NET MVC中获取当前用户 [英] How to get the current user in ASP.NET MVC
本文介绍了如何在ASP.NET MVC中获取当前用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在表单模型中,我曾经通过以下方式获取当前登录用户:
In a forms model, I used to get the current logged-in user by:
Page.CurrentUser
如何在ASP.NET MVC的控制器类中获取当前用户?
How do I get the current user inside a controller class in ASP.NET MVC?
推荐答案
如果您需要从控制器中获取用户,请使用Controller的用户
属性。如果您从视图中需要它,我会在 ViewData
中填充您特别需要的内容,或者您可以调用User,因为我认为它是 ViewPage
。
If you need to get the user from within the controller, use the User
property of Controller. If you need it from the view, I would populate what you specifically need in the ViewData
, or you could just call User as I think it's a property of ViewPage
.
这篇关于如何在ASP.NET MVC中获取当前用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文