我试图在 Visual Studio 2013 中调试时获取 Windows 用户名。我只是使用:
httpcontext.current.user.identity.name
如果我在我的开发服务器上运行它,它可以正常工作,如果我在任何以前版本的 Visual Studio 上以调试模式运行它,它也可以正常工作。
我的问题是 - 如果我在 Visual Studio 2013 上运行它,我会得到一个空字符串。
我的网络配置如下。
<system.web>
<authentication mode="Windows"/>
<identity impersonate="false"/>
<authorization>
<allow users="*"/>
</authorization>
<compilation debug="true" strict="false" explicit="true" targetFramework="4.0"/>
<customErrors mode="Off"/>
</system.web>
我刚刚从 VS 2012 升级到 VS 2013,当前用户身份 (HttpContext.User.Identity) 是匿名的。
我尝试更改 IIS Express applicationhost.config,没有区别。
解决方案是查看 Web 项目的属性,当您选择了项目的顶层时,按 F4 即可获取项目属性。不要右键单击项目并选择属性,这是完全不同的东西。
将匿名身份验证更改为禁用,将 Windows 身份验证更改为启用。
就像肉汁一样:)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)