How to Get the Currently Loggedin Windows Account from an ASP.NET Page

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

You have to set authentication mode to Windows in your configuration & also disable anonymous users in authorization tag.

How do I get the current Windows logged-in user's username?

It sounds like you may need to consider mixed-mode authentication. I.e. Windows and Forms authentication. The thing is they don't necessarily play well together.

The following article describes the problem and how to overcome it. The thrust of the article centres around how a 401 challenge (Windows authentication) and 302 redirect (forms authentication) are incompatible in > IIS 7 integrated mode and a way to use a couple of forms and HTTP pipeline interception to get at user details. I used the approach successfully for a large public sector client (albeit for a webforms application). I'm sure the principles are the same.

IIS 7.0 Two-Level Authentication with Forms Authentication and Windows Authentication

I forgot to add in the code examples the right place to look for Windows authentication credentials are presented. It's been a while, so I can't remember it off the top of my head.

How do you get the logged in Windows domain account from an ASP.NET application?

I did pretty much exactly what you want to do a few years ago. Im trying to find some code for it, though it was at a previous job so that code is at home.

I do remember though i used this article as my starting point. You set up the LDAP provider so you can actually run a check of the user vs the LDAP. One thing to make sure of if you try the LDAP approach. In the setting file where you set up the LDAP make sure LDAP is all caps, if it is not it will not resolve.

How do I get the current username in .NET using C#?

Option A)

string userName = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
  • Returns: NetworkName\Username
  • Gets the user's Windows logon name.
  • Details: https://docs.microsoft.com/en-us/dotnet/api/system.security.principal.windowsidentity

Option B)

string userName = Environment.UserName
  • Returns: Username
  • Gets the user name of the person who is associated with the current thread.
  • Details: https://docs.microsoft.com/en-us/dotnet/api/system.environment.username

How to get current user who's accessing an ASP.NET application?

If you're using membership you can do: Membership.GetUser()

Your code is returning the Windows account which is assigned with ASP.NET.

Additional Info Edit:
You will want to include System.Web.Security

using System.Web.Security

How to get currently logged in Windows user ID on client side

You need to use ASP.NET impersonation feature.
When using impersonation, ASP.NET applications can execute with the Windows identity (user account) of the user making the request. Impersonation is commonly used in applications that rely on Microsoft Internet Information Services (IIS) to authenticate the user.

Such behavior can be configured in web config using the following code:

<configuration>
<system.web>
<identity impersonate="true"/>
</system.web>
</configuration>

More info: http://msdn.microsoft.com/en-us/library/xh507fc5%28v=vs.100%29.aspx

How to get current logged in user of Domain of local system in mvc

If you have Windows Authentication working, then the current user is available in HttpContext.User.

User.Identity.Name will be the username.



Related Topics



Leave a reply



Submit