ASP.Net MVC4 User.Identity.Name越来越空,即使设定验证方式为“窗口” [英] ASP.Net MVC4 User.Identity.Name getting empty even though set authentication mode as 'Windows'

查看:458
本文介绍了ASP.Net MVC4 User.Identity.Name越来越空,即使设定验证方式为“窗口”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作ASP.Net MVC-4的应用程序。我要实现Windows身份验证。
我在web.config文件中设置验证方式为窗口,如下图所示。

I am working on ASP.Net MVC-4 application. I have to implement windows authentication. I have set authentication mode as 'Windows' in web.config file as shown below.

     <system.web>
          <authentication mode="Windows" />
     </system.web>

在控制器我尝试如下得到的用户名。

In controller I try to get username as below.

    string userName = User.Identity.Name;

但每次我得到空值。
请让我知道的任何建议。
先谢谢了。

but every time I am getting empty value. Please let me know for any suggestions. Thanks in advance.

推荐答案

Windows身份验证通过IIS进行建立我们的管理code User.Identity 。因此,你需要为在您的IIS启用Windows身份验证,然后以强制用户能够访问我们​​的应用程序之前进行身份验证,则需要为禁用匿名身份验证

Windows authentication is performed by IIS to establish our managed code User.Identity. Therefore, you need to enable Windows Authentication in your IIS, and in order to force the user to authenticate before being able to access our application, you need to disable Anonymous Authentication

这篇关于ASP.Net MVC4 User.Identity.Name越来越空,即使设定验证方式为“窗口”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆