【发布时间】:2013-04-20 19:38:24
【问题描述】:
我正在开发在我们的 Intranet 上运行的 ASP.NET MVC 应用程序。我们正在使用表单身份验证,但是设置的用户名将与 Active Directory 用户名相同。我正在尝试找到一种使用 Windows 用户名预填充登录用户名字段的方法,但找不到访问当前 Windows 用户身份的方法。
System.Environment.UserDomainName 返回“IIS APPPOOL”
System.Security.Principal.WindowsPrincipal.Current.Identity 返回一个 GenericIdentity
HttpContext.Request.LogonUserIdentity.Name 返回“NT AUTHORITY\IUSR”
我不想验证 Windows 用户或以 Windows 用户身份登录网站,我只想读取用户名。在使用表单身份验证而不是 Windows 身份验证时有什么方法可以做到这一点?
【问题讨论】:
-
我认为将
<identity impersonate="true" />添加到 webconfig (就在<authentication>位下方,而不是内部!)应该可以满足您的需求。那么Controller应该有一个User可以查询的属性,而不是上面的代码…… -
我刚刚试了一下,得到了 Principal.GenericIdentity
标签: asp.net .net asp.net-mvc iis-7 forms-authentication