473,387 Members | 1,342 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How to display username of visitor to page

I would like to display the username of the visitor top a web page. This is
assuming that the visitor is coming from within a winodws2000 Domain. I
have tried the following but it gives me the user ASPNET which I assume is
coming from the IIS server not the web client :

Imports System.Security.Principal

'Returns current user
Public Function CurrentUser()
Dim pos As Integer, fullname As String
fullname = System.Security.Principal.WindowsIdentity.GetCurre nt().Name
'Just to get at the username after the 'domainname\' Should really use
Substring instead of Mid
pos = InStr(fullname, "\", CompareMethod.Text)
CurrentUser =
Mid(System.Security.Principal.WindowsIdentity.GetC urrent().Name, pos + 1)
End Function
'To test whether user is a member of a group
Private Function InGroup(ByVal grp As String) As Boolean
Dim id As WindowsIdentity
id = WindowsIdentity.GetCurrent()
Dim p As New WindowsPrincipal(id)
InGroup = p.IsInRole("YourDomainName\" + grp)
End Function

.....and a sample Sub Main()....

Sub Main()
dim msg as string
If InGroup("AppUsers") Then
Application.Run(New YourMainForm)
Else
msg = "You are not a registered user. Please go away."
MessageBox.Show(msg, "Invalid user", MessageBoxButtons.OK)
End If
End Sub
Nov 20 '05 #1
5 7758
I have also tried "Environment.Username" which gives me ASPNET and
"System.Web.HttpContext.Current.User.Identity.Name .ToString()" which gives
me nothing at all.

Any help?
Nov 20 '05 #2
Turns out I had to turn off IIS anonymous connections.

"Fred" <fb******@centralstatesmfg.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
I have also tried "Environment.Username" which gives me ASPNET and
"System.Web.HttpContext.Current.User.Identity.Name .ToString()" which gives
me nothing at all.

Any help?

Nov 20 '05 #3
for this to work you need to turn off anonymous access in IIS settings for
your website

"Fred" <fb******@centralstatesmfg.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
I have also tried "Environment.Username" which gives me ASPNET and
"System.Web.HttpContext.Current.User.Identity.Name .ToString()" which gives
me nothing at all.

Any help?

Nov 20 '05 #4
IIS Settings > website you want to enable on > properties > Directory
security tab > edit
uncheck anonymous access and turn integrated windows authentication
"Fred" <fb******@centralstatesmfg.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
I have also tried "Environment.Username" which gives me ASPNET and
"System.Web.HttpContext.Current.User.Identity.Name .ToString()" which gives
me nothing at all.

Any help?

Nov 20 '05 #5
To clarify for anyone who has the same problem I used
System.Web.HttpContext.Current.User.Identity.Name. ToString() but had to turn
off IIS anonymous authentication per Brian Henry's response.

Fred

"Fred" <fb******@centralstatesmfg.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
I have also tried "Environment.Username" which gives me ASPNET and
"System.Web.HttpContext.Current.User.Identity.Name .ToString()" which gives
me nothing at all.

Any help?

Nov 20 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: danubian | last post by:
Hi, I'm a newbie in php/mysql programming,really am. I'm working on a web-site that allows registration and posterior logging in. Already registered user logs in with valid username and...
6
by: Bob Lin | last post by:
I would like to display the hostname (or computername) and username (or logonID) on our Intranet support page. I saved the following vbs code as asp file, but it doesn't display the username. No...
4
by: Mikael | last post by:
Hi all, I would like to display all logged in member on my webpage. example 3 Inlogged members : adam cesar Mike ....
2
by: Whitney | last post by:
I've been going bonkers trying to find the answer to this question... I'm hoping somebody out there can help me. Our network environment is Active Directory and our web server is Windows 2003 IIS...
2
by: Hari | last post by:
Hi, How can I find out what site a visitor has come from using ASP? Suppose my website is sample.com and I have one page in the website that is used by the visitor to request products and...
12
by: FluffyCat | last post by:
New on November 28, 2005 for www.FluffyCat.com PHP 5 Design Pattern Examples - the Visitor Pattern. In the Visitor pattern, one class calls a function in another class and passes an instance of...
17
by: Merlin | last post by:
Probably there is no right or wrong answer to this but I thought to ask to put my mind at rest. Ok lets say you have a object hierarchy (eg. the Glyph in Lexi from GOF book) and you want to use the...
3
by: bb nicole | last post by:
Below is my login function, it can work well, but after i include it at my homepage, the print message is in the login page... What should it do to make the print message invalid username or...
3
by: Ken Fine | last post by:
I am using ASP.NET's CreateUserWizard control. I want to force the visitor to use a username and e-mail address that I am providing in programming, and I do not want the visitor to be able to edit...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.