how to get aspx page username ?

2008-04-30


in vb its system.environment.username - whats the equivalent in aspx with code behind (VB) ?


In the codebehind of your aspx code, you could use:

Page.User.Identity.Name ;

In a custom class, you could use: HttpContext.Current.User.Identity.Name;


thanks but niether seems to work - aspx accepts it but it does nothing!


It depends how you would like to use it.

If you want to get the Windows username you have to make sure you disabled anonymous access in IIS.

If you use forms authentication you can make a custom principal: System.Security.Principal.GenericIdentity identity = new System.Security.Principal.GenericIdentity("testUse rName"); System.Security.Principal.GenericPrincipal principal = new System.Security.Principal.GenericPrincipal(identit y,new string[]{ "TestRole"});

Context.User = principal;