how to get username ?

L

luna

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

cheers

mark
 
K

Kristof Van Praet

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
 
K

Kristof Van Praet

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
 
L

luna

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,049
Latest member
Allen00Reed

Latest Threads

Top