asp.net-mvc-3 - 如何让 User.Identity 在 Controller 外工作

标签 asp.net-mvc-3

我的一些自定义 ASP.NET MVC 助手有单独的项目

在我的一个助手中,我需要检查用户身份。

我怎样才能得到 User.Identity在那里工作?

默认情况下,它位于 System.Security.Principal在名为 interface IPrincipal 的界面中

最佳答案

您可以通过以下方式更轻松地访问它:

HttpContext.Current.User.Identity

所以 HttpContext.Current 是诀窍。

关于asp.net-mvc-3 - 如何让 User.Identity 在 Controller 外工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5898170/

相关文章:

asp.net - 未定义无参数构造函数对象

c# - 如何在ajax调用后重置表单

asp.net-mvc-3 - 将图像放在 CDN 上,在 IIS7 上使用 MVC3

ASP.Net MVC3 Razor Href 错误

asp.net-mvc - 为什么要调用base.OnActionExecuting(filterContext);?

c# - 处理选择列表

mysql - 如何在 Orchard CMS 1.3.10 中使用 MySQL 数据库?

c# - C# 中的 Twitch TV OAuth 登录

c# - MVC 3 Razor-如何处理成功/错误消息

asp.net - 我可以通过通用的 try/catch 优雅地运行 Controller 中的每个 ContentResult 吗?