如何在 ASP.NET MVC 中获取当前用户 [英] How to get the current user in ASP.NET MVC

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

问题描述

在表单模型中,我曾经通过以下方式获取当前登录用户:

Page.CurrentUser

如何在 ASP.NET MVC 中的控制器类中获取当前用户?

解决方案

如果您需要从控制器内部获取用户,请使用控制器的 User 属性.如果您从视图中需要它,我会在 ViewData 中填充您特别需要的内容,或者您​​可以直接调用 User,因为我认为它是 ViewPage 的一个属性.>

In a forms model, I used to get the current logged-in user by:

Page.CurrentUser

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

解决方案

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屋!

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