Environment.UserName returning application pool name instead of username

前端 未结 4 746
后悔当初
后悔当初 2021-01-05 06:57

The following line

Environment.UserName

In debug mode in visual studio returns the identity of the user like I need.

Then when I se

相关标签:
4条回答
  • 2021-01-05 07:36

    In IIS, for your application, please . Enable ASP.NET Impersonation

    0 讨论(0)
  • 2021-01-05 07:43

    This worked for me. Use Environment.GetEnvironmentVariable("USERNAME") for current Login username.

    Link :https://www.c-sharpcorner.com/uploadfile/puranindia/the-environment-class-in-C-Sharp/

    0 讨论(0)
  • 2021-01-05 08:00

    Try something like this:

    if (System.Web.HttpContext.Current.User.Identity.IsAuthenticated)
    {
       string username = System.Web.HttpContext.Current.User.Identity.Name;
    }
    

    Important note: You need to configure IIS to enable integrated security and disable anonymous logon.

    Note that Environment.Username returns the Username on the current Thread.

    0 讨论(0)
  • 2021-01-05 08:01

    Try using

    Request.ServerVariables["LOGON_USER"]
    

    It will return DOMAIN\USERNAME. You can then split it etc.

    0 讨论(0)
提交回复
热议问题