asp.net mvc - Get current logged in username -


I want to get the user name of the current logged in user. I am using code below but it returns to the user who is identified in the IIS application pool identity. I MVC website is posted on a server

I

String User ID = System Security Principal. Windows Identity GetCurrent () Name.ToString ();

string userid = Environment.UserName;

string userid = System.DirectoryServices.AccountManagement.UserPrincipal.Current.GivenName.ToString ();

string userid = system. Web. HTTPPTX.Corrent.USArIndentityNameString ()

But I do not feel anything to answer the correct answer.

I need to get the user name in the constructor of HomeController .

Below on my web. Config

  & lt; Authentication mode = "Windows" /> & Lt; Authority & gt; & Lt; Allow users = "*" /> & Lt; / Authorization & gt;  

instead of just

  string userid = system .Web.HttpContext.Current.User.Identity.Name.ToString ()  

Use it, it will work properly

  string userid = HttpContext Current .User Recognise. Name. Toaster ()  

Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -