We have an ASP.NET intranet site, available to users who are either physically at and logged into a local machine or else to users who connect remotely via VPN. Is there a way to automatically get the username of whoever is accessing the page based on the name used to either log into the local machine or that used for the VPN?
views:
1379answers:
5
A:
If the authentication is setup to do Integrated Windows authentication then you should be able to get it by accessing
User.Identity.Name
Dave
2009-04-17 16:05:52
A:
If the authentication is windows, this should help:
IIdentity WinId= HttpContext.Current.User.Identity;
WindowsIdentity wi = (WindowsIdentity)WinId;
Gulzar
2009-04-17 16:07:38
I just get an empty string
notnot
2009-04-17 16:21:11
for name property?
Gulzar
2009-04-17 16:29:34
yes, the name is blank
notnot
2009-04-17 16:33:17
are you using Forms or Windows authentication?
Gulzar
2009-04-17 16:39:37
Turns out the problem was that our admin had set anonymous access to true
notnot
2009-04-17 19:45:40
aah i see. check out the section on anonymous access http://www.eggheadcafe.com/articles/20050703.asp
Gulzar
2009-04-17 19:54:31
+2
A:
This is possible if you're using Windows Authentication in your pages.
You can use either Page.User.Identity.Name
or the more complete System.Web.HttpContext.Current.User.Identity.Name
.
Read more about it here:
Enabling Windows Authentication within an Intranet ASP.NET Web Application
If you are, however, using Forms Authentication, you'll have to keep track of the current user yourself, the most common method of which will be by storing their login name in a Session variable.
Jon Limjap
2009-04-17 16:11:46