Tag Archives: c#

Debugging A .NET Service With “Attach To Process” In Visual Studio

The tricky thing about building a Windows service is the debugging.   You cant just hit F5 and debug the app from there,  you need to “Attach” to the process.

Thankfully its not very difficult, although some of the guides out there aren’t very clear on this , so follow the following steps and you’ll be debugging in no time.

Continue reading “Debugging A .NET Service With “Attach To Process” In Visual Studio” »

Get Logged In User With ASP.Net

Using the following three ways we can get the User Name using C#

1
2
System.Security.Principal.WindowsPrincipal p = System.Threading.Thread.CurrentPrincipal as System.Security.Principal.WindowsPrincipal;
string strName = p.Identity.Name;

1
string strName = HttpContext.Current.User.Identity.Name.ToString();

1
2
string strName = Request.ServerVariables["AUTH_USER"]; //Finding with name
string strName = Request.ServerVariables[5]; //Finding with index

In Above 3 Cases returning string contains DomainName\WinNTLoggedUserName

(for Ex: Microsoft\Bill.Gates. Here Microsoft is domain Bill.Gates is Logger User Name )

Using string operations seperate the DomainName and UserName.