我与我的一些自定义ASP.NET MVC助手有单独的项目
在我的一位助手中,我需要检查用户身份.
我怎么能User.Identity在那里工作?
默认情况下它System.Security.Principal位于名为的界面中interface IPrincipal
Zok*_*oka 50
您可以通过以下方式轻松访问它:
HttpContext.Current.User.Identity
Run Code Online (Sandbox Code Playgroud)
所以HttpContext.Current就是诀窍.
Dan*_*elB 12
HtmlHelper具有当前的ViewContext,通过HttpContext,您将获得当前用户的User对象.在您的扩展方法中,您可以使用此方法
public static bool MyHelper(HtmlHelper helper)
{
var userIdentity = helper.ViewContext.HttpContext.User.Identity;
// more code
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9542 次 |
| 最近记录: |