简体   繁体   English

Windows身份验证在IIS中不起作用

[英]Windows authentication not working in IIS

I am using .net 4.5 and mvc4.I want to get the name of currently logged in machine user. 我正在使用.net 4.5和mvc4。我想获取当前登录的计算机用户的名称。 It is working locally but when I deployed on IIS it's not working.If I enable anonymous authentication then it's working but site asks for login every time which is not required. 它在本地工作,但是当我在IIS上部署时却无法工作。如果启用了匿名身份验证,那么它就可以工作,但是网站每次都要求登录,而这不是必需的。 Any idea that this should work without logging in everytime? 是否知道无需每次登录都可以正常工作?

You probably need to leave enabled APS.NET-Impersonation and Windows Authentication, and disable all the other authentication methods. 您可能需要保留启用的APS.NET模拟和Windows身份验证,并禁用所有其他身份验证方法。 Also make sure that Impersonation is not enabled in your web.config ( <identity impersonate="false" /> ). 另外,请确保未在您的web.config( <identity impersonate="false" /> )中启用<identity impersonate="false" /> More info here (See figure 3) 此处有更多信息(请参见图3)

How do you access the user info? 您如何访问用户信息? The HttpContext should give you the currently logged in user, when the IIS authentication methods are properly setup. 正确设置IIS身份验证方法后,HttpContext应该为您提供当前登录的用户。

Dim identity = System.Security.Principal.WindowsIdentity.GetCurrent(False) Dim httpContextIndentity = HttpContext.Current.User.Identity Response.Write(String.Format("<p>Running as: {0}</p>", identity.Name)) Response.Write(String.Format("<p>User identity: {0}</p>", httpContextIndentity.Name))

Anonymous authentication mist be disabled, Windows authentication must be enabled. 禁用匿名身份验证,必须启用Windows身份验证。 Follow last post in this thread and check if your setup is correct. 按照此主题中的最新帖子并检查您的设置是否正确。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM