I want to check the login name of a user using windows authentication. I have this as a constructor of my controller:
public class HomeController : BaseController
{
    public string UserIdentityName;
    public HomeController()
    {
        UserIdentityName = System.Web.HttpContext.Current.User.Identity.Name;// HttpContext.Current.User.Identity.Name;
    }
}
But UserIdentityName returns empty string...
I also have this at my web.config:
<authentication mode="Windows" />   
any idea?
In solution explorer pane select the Web Project and hit F4. (not right click+properties, thats different)
In properties Pane set:
Windows Authentication: Enable 
Anonymous Authentication: Disabled
In Web.config: <authentication mode="Windows"></authentication>
To get Username: 
HttpContext.Current.User.Identity.Name OR User.Identity.Name
Run your project, Happy Days!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With