how to get username ?

  • Thread starter Thread starter luna
  • Start date Start date
L

luna

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

cheers

mark
 
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;

Hope this helps,

Kristof
 
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("testUserName");
System.Security.Principal.GenericPrincipal principal = new
System.Security.Principal.GenericPrincipal(identity,new string[]{
"TestRole"});

Context.User = principal;



Hope this helps,

Kristof
 
thats great!

works fine now
thanks!
mark


Kristof Van Praet said:
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("testUserName");
System.Security.Principal.GenericPrincipal principal = new
System.Security.Principal.GenericPrincipal(identity,new string[]{
"TestRole"});

Context.User = principal;



Hope this helps,

Kristof




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

thanks

mark
 
Back
Top