How do I get the currently loggedin Windows account from an ASP.NET page?

前端 未结 8 1010
余生分开走
余生分开走 2020-12-01 12:25

I have an ASP.NET 3.5 application that uses ASP.NET forms authentication. I want to be able to get the Windows user name currently logged into the computer (NOT logged into

8条回答
  •  悲哀的现实
    2020-12-01 12:49

    I managed to resolve this issue by following the instructions on here in Method 1 at the following link - https://support.microsoft.com/en-us/help/896861/you-receive-error-401-1-when-you-browse-a-web-site-that-uses-integrate In brief, Disable all Authentication methods except Windows Authentication. Open regedit under an admin account, locate HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa\MSV1_0, right click the node and go New, and select Multi-String Value. Enter "BackConnectionHostNames" and click Enter. For Value enter the website you're trying to set access on and click OK. Restart IIS Once I'd done that I was able to get the current windows user using HttpContext.Current.User.Identity.Name, WindowsPrincipal(this.Request.LogonUserIdentity) also got me the Windows username logged in. For reference System.Environment.UserName and System.Security.Principal.WindowsIdentity.GetCurrent().Name, both of these still gave the IIS user.

    This has taken me ages to get to the bottom of. Good luck with it. IIS is a waking nightmare!

提交回复
热议问题