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

由网友(北葵向暖)分享简介:在表格模型中,我用来获取当前登录的用户通过In forms model, I used to get current logged in user byPage.CurrentUser我要如何在ASP.NET MVC控制器类中当前用户?How do I get current user inside a cont...

在表格模型中,我用来获取当前登录的用户通过

In forms model, I used to get current logged in user by

Page.CurrentUser

我要如何在ASP.NET MVC控制器类中当前用户?

How do I get current user inside a controller class in ASP.NET MVC?

推荐答案

如果您需要在控制器内获得用户,使用用户控制器的性能。如果您认为需要的话,我会填充你特别需要在的ViewData ,或者你可以只调用用户,因为我认为这是一个属性的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.