在我的控制器类内我有私有方法,它返回使用User.Identity.Name作为参数获取的记录用户,这一切都很好。User.Identity.Name非静态字段需要对象引用
private static Account GetLoggedUser()
{
AccountService accService = new AccountService();
Account userAccount = accService.GetAccountByUsername(User.Identity.Name);
return userAccount;
}
public ActionResult Edit()
{
var userAccount = GetLoggedUser();
...
}
问题是,我上线User.Identity.Name
一个对象引用是所必需的非静态字段, 方法,或属性“得到这个错误System.Web.Mvc.Controller .User.get'
在编译时显示错误。
你可以通过'User.Identity.Name'吗?或者你可以使用'PrincipalContect'来获得它,你需要传入当前用户,你可以在'Page Level'中获得它,如果你的方法需要'DomainName \\ UserName'中的用户名传递'Split' (“\\”)'方法的名称和传递字符串[1]'价值 – MethodMan 2013-02-16 20:36:24