PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, September 2, 2022

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

 September 02, 2022     active-directory, asp.net-mvc, authentication, c#, windows-authentication     No comments   

Issue

I have an application for an organization where a user will logged in to his system with domain user, so now I want to get that logged in user. I tried many methods and get username locally, but my application is on IIS and it gets the IIS user with IIS APPPool\DefaultAppPool while system name and domain get but username not.

This is the code I am using for getting username:

Request.ServerVariables.Get("logon_user");
System.Security.Principal.WindowsIdentity.GetCurrent().Name;
Environment.GetEnvironmentVariable("USERNAME");
System.Security.Principal.WindowsPrincipal(System.Security.Principal.WindowsIdentity.GetCurrent()).Identity.Name;

If someone knows how to get local username rather than IIS, please share. Thanks in advance.


Solution

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

User.Identity.Name will be the username.



Answered By - Gabriel Luci
Answer Checked By - Dawn Plyler (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing