【发布时间】:2016-06-13 08:46:06
【问题描述】:
这可能是重复问题,但我没有从其他帖子中找到任何解决方案。
我正在使用 Windows 身份验证,当我在本地系统上构建应用程序时,它工作正常,但是当我在 IIS 上部署应用程序时,HttpContext.Current.User.Identity.Name 返回 null。我在身份验证设置上禁用了除 Windows 身份验证之外的所有内容。
var strUserName = HttpContext.Current.User.Identity.Name == "" ? System.Security.Principal.WindowsIdentity.GetCurrent().Name : HttpContext.Current.User.Identity.Name;
我的 strUserName 为空。
<authentication mode="Windows">
</authentication>
<identity impersonate="true"/>
我尝试分割线并编写代码来检查究竟是什么返回...
HttpContext.Current.User.Identity.Name is returning null
System.Security.Principal.WindowsIdentity.GetCurrent().Name is returning NT AUTHORITY\IUSR when impersonate is true
System.Security.Principal.WindowsIdentity.GetCurrent().Name is returning IIS APPPOOL\ApplicationPoolName when impersonate is false
我检查过以下几个链接
【问题讨论】:
-
我想向您推荐edit 您的问题并添加您发现的其他类似问题,并尽量避免将您的问题标记为重复。
-
我相信第二个
<authentication>标签会覆盖上面示例中的第一个标签,因此mode=Windows不会被拾取。可以尝试合并两个配置项吗? -
你指的是服务/WCF吗?
标签: c# asp.net authentication