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

前端 未结 8 1223
粉色の甜心
粉色の甜心 2020-11-29 06:24

To get the current logged in user at the system I use this code:

string opl = System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString();
         


        
8条回答
  •  时光说笑
    2020-11-29 06:54

    Using System.Web.HttpContext.Current.User.Identity.Name should work. Please check the IIS Site settings on the server that is hosting your site by doing the following:

    1. Go to IIS → Sites → Your Site → Authentication

      IIS Settings

    2. Now check that Anonymous Access is Disabled & Windows Authentication is Enabled.

      Authentication

    3. Now System.Web.HttpContext.Current.User.Identity.Name should return something like this:

      domain\username

提交回复
热议问题