Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Security > How can I get the domain name and username?

Reply
Thread Tools

How can I get the domain name and username?

 
 
Cherry Adriano
Guest
Posts: n/a
 
      12-11-2003
I'm new with .net programming....so pls bear with me. May
I ask how can I get the domain name and username of user
who is trying access my web application.
 
Reply With Quote
 
 
 
 
Chris Jackson
Guest
Posts: n/a
 
      12-11-2003
System.Web.HttpContext.User.Identity.Name will return a string in the form
domain\userName.

--
Chris Jackson
Software Engineer
Microsoft MVP - Windows Client
Windows XP Associate Expert
--
More people read the newsgroups than read my email.
Reply to the newsgroup for a faster response.
(Control-G using Outlook Express)
--

"Cherry Adriano" <(E-Mail Removed)> wrote in message
news:095801c3bfb7$eebeade0$(E-Mail Removed)...
> I'm new with .net programming....so pls bear with me. May
> I ask how can I get the domain name and username of user
> who is trying access my web application.



 
Reply With Quote
 
 
 
 
John Soulis [MSFT]
Guest
Posts: n/a
 
      12-11-2003
Hello Cherry,
Add this to your web.config file. This file is in the solution files in
Visual Studio .NET.
<identity impersonate="true" />

Then you can use this line of code.
System.Security.Principal.WindowsIdentity.GetCurre nt().Name)

I hope this helps you.

Best regards,
John Soulis
Microsoft, ASP.NET

This posting is provided "AS IS", with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm

 
Reply With Quote
 
cherry_adriano@yahoo.com
Guest
Posts: n/a
 
      12-16-2003
Sir Chris,
System.Web.HttpContext.User.Identity.Name returns
domain\username where domain is my computer name and
username as ASPNET. Do you know how can I get network
logon name(username) and domain used in logging on to
Operating System?

There is a way to get the network logon name using vb6 .
See VB6 script below. How can I get this in VB.net Thanks
=)

Private Declare Function w32_WNetGetUser Lib "mpr.dll"
Alias "WNetGetUserA" (ByVal lpszLocalName As String, ByVal
lpszUserName As String, lpcchBuffer As Long) As Long
Private Sub Form_Load()
'KPD-Team 1998
'URL: http://www.allapi.net/
'E-Mail: http://www.velocityreviews.com/forums/(E-Mail Removed)
Dim lpUserName As String, lpnLength As Long, lResult
As Long
'Create a buffer
lpUserName = String(256, Chr$(0))
'Get the network user
lResult = w32_WNetGetUser(vbNullString, lpUserName,
256)
If lResult = 0 Then
lpUserName = Left$(lpUserName, InStr(1,
lpUserName, Chr$(0)) - 1)
MsgBox "The user's Network Logon Name is " +
lpUserName + ".", vbInformation + vbOKOnly, App.Title
Else
MsgBox "No user found !", vbExclamation +
vbOKOnly, App.Title
End If
End Sub
>-----Original Message-----
>System.Web.HttpContext.User.Identity.Name will return a

string in the form
>domain\userName.
>
>--
>Chris Jackson
>Software Engineer
>Microsoft MVP - Windows Client
>Windows XP Associate Expert
>--
>More people read the newsgroups than read my email.
>Reply to the newsgroup for a faster response.
>(Control-G using Outlook Express)
>--
>
>"Cherry Adriano" <(E-Mail Removed)> wrote in

message
>news:095801c3bfb7$eebeade0$(E-Mail Removed)...
>> I'm new with .net programming....so pls bear with me.

May
>> I ask how can I get the domain name and username of user
>> who is trying access my web application.

>
>
>.
>

 
Reply With Quote
 
Cherry Adriano
Guest
Posts: n/a
 
      12-16-2003

Sir Chris,
System.Web.HttpContext.User.Identity.Name returns domain\username where
domain is my computer name and username as ASPNET. Do you know how can I
get network logon name(username) and domain used in logging on to
Operating System?

There is a way to get the network logon name using vb6 . See VB6 script
below. How can I get this in VB.net Thanks =)

Private Declare Function w32_WNetGetUser Lib "mpr.dll" Alias
"WNetGetUserA" (ByVal lpszLocalName As String, ByVal lpszUserName As
String, lpcchBuffer As Long) As Long
Private Sub Form_Load()
'KPD-Team 1998
'URL: http://www.allapi.net/
'E-Mail: (E-Mail Removed)
Dim lpUserName As String, lpnLength As Long, lResult As Long
'Create a buffer
lpUserName = String(256, Chr$(0))
'Get the network user
lResult = w32_WNetGetUser(vbNullString, lpUserName, 256)
If lResult = 0 Then
lpUserName = Left$(lpUserName, InStr(1, lpUserName, Chr$(0)) -
1)
MsgBox "The user's Network Logon Name is " + lpUserName + ".",
vbInformation + vbOKOnly, App.Title
Else
MsgBox "No user found !", vbExclamation + vbOKOnly, App.Title
End If
End Sub


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
John Soulis [MSFT]
Guest
Posts: n/a
 
      12-16-2003
Hello Cherry,
Did you add <identity impersonate="true" /> this to the web.config file and
you need to have windows integrated select too in the directory security of
your application root.
Thank you,
John Soulis
Microsoft, ASP.NET

This posting is provided "AS IS", with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm

 
Reply With Quote
 
Chris Jackson
Guest
Posts: n/a
 
      12-16-2003
> Sir Chris,

NICE! I have been knighted!

John's answer is absolutely correct, this pulls the user token that is being
used by the process for external calls. You have to have BOTH ASP.NET and
IIS configured for Windows Authentication. The complete identity matrix can
be found here:

http://msdn.microsoft.com/library/de...SecNetAP05.asp

--
Chris Jackson
Software Engineer
Microsoft MVP - Windows Client
Windows XP Associate Expert
--
More people read the newsgroups than read my email.
Reply to the newsgroup for a faster response.
(Control-G using Outlook Express)
--


 
Reply With Quote
 
Cherry
Guest
Posts: n/a
 
      01-19-2004
I already added <identity impersonate="true" /> to the Web.Config file, however, error similar below was encountered

"An error occurred while try to load the string resources (GetModuleHandle failed with error 126)."

Please help. thanks =)


 
Reply With Quote
 
John Soulis [MSFT]
Guest
Posts: n/a
 
      01-20-2004
Grant ASPNET account "Impersonate a client after authentication" privilege.

Thank you,
John Soulis
Microsoft, ASP.NET

This posting is provided "AS IS", with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
How to get domain name from domain camper with fake whois? Nik Coughlin NZ Computing 4 12-08-2008 08:42 PM



Advertisments