我在MVC 5上具有表单身份验证的应用程序托管在Azure上的Windows Server(2012)上。还将此服务器添加到域中。
我的客户要求我使用Windows凭据而不是表单身份验证来对用户进行身份验证。
因此,我更改了用于身份验证的web.config条目,如下所示:
<system.web>
<authentication mode="Windows"/>
<identity impersonate="true" />
</system.web>
和
<system.webServer>
<security>
<authentication>
<windowsAuthentication enabled="true" useKernelMode="true">
<providers>
<clear />
<add value="NTLM" />
<add value="Negotiate" />
</providers>
<extendedProtection tokenChecking="Allow" />
</windowsAuthentication>
<anonymousAuthentication enabled="false" />
</authentication>
</security>
</system.webServer>
其余的IIS v-8.5)设置如下:
仍然,我无法通过以下任何方式获取Windows用户电子邮件或用户名:
uname=User.Identity.Name;
uname=UserPrincipal.Current.EmailAddress;
uname= Environment.UserName;
我想念什么?
答案 0 :(得分:0)
您可以使用@ HttpContext.Current.User.Identity.Name,因为您的配置设置为使用Windows身份验证。许多浏览器会透明地传递用户名。
有关其他解决方法,请参考this thread。