问题描述
当我尝试
user = System.Web.UI.Page.CurrentUser
或
user = System.Web.UI.Page.User.Identity
我得到一个错误,指出该方法不适合System.Web.UI.Page定义
I get an error saying that the method is not defined for System.Web.UI.Page
我想一个控制器内访问它,它是怎么回事?
I am trying to access it within a Controller, does that matter?
我检查,我没有叫页另一个类,它为什么会说没有定义的方法?
I checked that I do not have another class named Page, Why would it say the method is not defined?
推荐答案
有很多方法可以做到这一点(基本上,他们都是一样的)
There are many ways to do it (basically, they are all the same)
User.Identity // in the controller
HttpContext.User.Identity // in the controller
System.Web.HttpContext.Current.User.Identity // anywhere
Page.User
物业工作时,有一个页
HTTP处理程序的处理当前请求。作为一个MVC控制器,该请求并没有流传到页
类,它不会工作。
Page.User
property works when there's a Page
HTTP handler that's processing the current request. As in an MVC controller, the request has not been handed to a Page
class, it won't work.
在控制器中。
这篇关于System.Web.UI.Page不会让我访问的currentUser或User.Identity在ASP.Net MVC的一个控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!