简体   繁体   English

无法在ASP.NET中使用“ User.Identity.Name”获取Windows用户名

[英]Not able to get the Windows User Name using 'User.Identity.Name' in ASP.NET

I am trying to use 'MsgBox(User.Identity.Name)' to show the Current Windows User in a MessageBox. 我正在尝试使用“ MsgBox(User.Identity.Name)”在MessageBox中显示当前Windows用户。 The MessageBox that appears shows "App_Web_1gu0lxe5" as the Title and Message is Empty. 出现的消息框显示“ App_Web_1gu0lxe5”,因为标题和消息为空。 In other words I am not able to get the Current Windows User in the Output. 换句话说,我无法在输出中获得“当前Windows用户”。

I am using Windows 8.1 Enterprise, 64-bit Operating System, Microsoft Visual Studio 2012, Visual Basic is the Programming Language and I am trying to develop a Web Application. 我正在使用Windows 8.1企业版,64位操作系统,Microsoft Visual Studio 2012,Visual Basic是编程语言,并且我正在尝试开发Web应用程序。

When I am running the same code on a Machine running "Windows 7 Enterprise, Service Pack 1, 64-bit Operating System" the code produces the desired result. 当我在运行“ Windows 7 Enterprise,Service Pack 1,64位操作系统”的计算机上运行相同的代码时,该代码将产生所需的结果。

Any Idea what could be the cause of the Problem? 任何想法可能是问题的原因吗?

You probably had Anonymous Authentication on as well as Windows Authentication. 您可能同时具有匿名身份验证和Windows身份验证。 Turn off Anonymous off. 关闭匿名关闭。

So, 所以,

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

In IIS config for the app, look in Authentication tab 在应用程序的IIS配置中,在“身份验证”选项卡中查找

Set Anonymous Authentication to Disabled and Set Windows Authentication to Enabled 匿名身份验证设置为禁用,并将Windows身份验证设置为启用

This should work and the Identity.UserName should now show up properly. 这应该可以正常工作,并且Identity.UserName现在应该正确显示。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在ASP.NET MVC中使用Windows身份验证时,User.Identity.Name没有返回正确的凭据 - User.Identity.Name is not returning the correct credentials when using Windows Authentication in ASP.NET MVC ASP.NET User.Identity.Name替代? - ASP.NET User.Identity.Name alternative? 在PHP中检索ASP.Net的User.Identity.Name - Retrieve ASP.Net's User.Identity.Name in PHP IIS7上的ASP.NET身份验证问题-Windows身份验证的User.Identity.Name为空 - ASP.NET Authentication Issues on IIS7 - User.Identity.Name is empty for Windows authentication User.Identity.Name 在使用 ASP.NET MVC 4 进行身份验证后得到 null - User.Identity.Name is getting is null after authentication using ASP.NET MVC 4 User.Identity.Name - User.Identity.Name 即使将身份验证模式设置为“Windows”,ASP.Net MVC4 User.Identity.Name也会变为空 - ASP.Net MVC4 User.Identity.Name getting empty even though set authentication mode as 'Windows' 测试使用User.Identity.Name的Asp.Net控制器操作方法? - Test an Asp.Net Controller action method which uses User.Identity.Name? ASP.NET Web 表单应用程序 User.Identity.Name 在 IIS 中不起作用 - ASP.NET web form application User.Identity.Name not working in IIS 如何在ASP.NET中使用User.Identity.Name作为SqlDataSource的参数? - How to use User.Identity.Name as a parameter for SqlDataSource in ASP.NET?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM