Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 ASP.NET
 capturing username (intranet)

Author  Topic 

SubPar_Coder
Starting Member

23 Posts

Posted - 2005-05-10 : 12:00:33
I have a asp page on our company's intranet and i want to capture the username that inputs information into the page. I don't make users log in into the webpage since this page is only available within our domain. Is this possible?

Jack of all trades, Master of none!

Merkin
Funky Drop Bear Fearing SQL Dude!

4970 Posts

Posted - 2005-05-10 : 17:58:00
ASP or ASP.NET ?

You need nt authentication to be enabled at the server for this to work.

In ASP, you get the Request.Servervariables("REMOTE_USER") (check that, I think it's right) and do some string parsing to remove the domain part and just get the username.

In asp.net it's similar, but you can get the name by looking at the user of the current Http Context.

Something like :

HttpContext current = HttpContext.Current;
string name = current.User.Identity.Name;
name = name.Substring(name.IndexOf("\\") + 1); //parsing out the domain.




Damian
Ita erat quando hic adveni.
Go to Top of Page

SubPar_Coder
Starting Member

23 Posts

Posted - 2005-05-10 : 18:10:14
I'm running asp.net

Jack of all trades, Master of none!
Go to Top of Page

Merkin
Funky Drop Bear Fearing SQL Dude!

4970 Posts

Posted - 2005-05-10 : 19:19:40
So does that answer your question ?


Damian
Ita erat quando hic adveni.
Go to Top of Page

SubPar_Coder
Starting Member

23 Posts

Posted - 2005-05-10 : 20:30:20
I think so. I will have to tinker with my webpage and see how it works.



Jack of all trades, Master of none!
Go to Top of Page

Merkin
Funky Drop Bear Fearing SQL Dude!

4970 Posts

Posted - 2005-05-10 : 20:58:40
You're welcome

Damian
Ita erat quando hic adveni.
Go to Top of Page

jhermiz

3564 Posts

Posted - 2005-05-13 : 09:56:02
Doesnt the domain come in the form of DOMAIN\UserName?

Using a bit of damian's code, translated into vb.net and changing SubString, try this:


Dim current As HttpContext
Dim strName As String

current = HttpContext.Current
strName = current.User.Identity.Name
strName = strName.Substring(strName.IndexOf("\") + 1)
Response.Write(strName)


Ensure that enable anon access is disabled on IIS-2 otherwise it will use the IUSR account.
This will only work with WIN Authentication...to verify you can try Response.Writing the current.User.Identity.AuthenticationType
property.

Jon



Keeping the web experience alive -- [url]http://www.web-impulse.com[/url]
Imperfection living for perfection --
[url]http://jhermiz.blogspot.com/[/url]
Go to Top of Page
   

- Advertisement -