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

前端 未结 8 1204
粉色の甜心
粉色の甜心 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:09

    If you're using membership you can do: Membership.GetUser()

    Your code is returning the Windows account which is assigned with ASP.NET.

    Additional Info Edit: You will want to include System.Web.Security

    using System.Web.Security
    

提交回复
热议问题