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

前端 未结 8 1222
粉色の甜心
粉色の甜心 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 07:04

    The quick answer is User = System.Web.HttpContext.Current.User

    Ensure your web.config has the following authentication element.

    
        
            
            
                
            
        
    
    

    Further Reading: Recipe: Enabling Windows Authentication within an Intranet ASP.NET Web application

提交回复
热议问题