Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Professional For advanced ASP.NET 1.x coders. Beginning-level questions will be redirected to other forums. NOT for "classic" ASP 3 or the newer ASP.NET 2.0 and 3.5
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 16th, 2003, 07:44 PM
Registered User
 
Join Date: Jul 2003
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Determine User Name at Runtime

I am writing an intranet application which has a welcome screen which needs to determine the user name of the person logged into the computer accessing the site.

What .net technology do I need to use.

DirectoryServices? (That only lets me manipulate the Active Directory, not determine the current logged in user.)

Environment.UserName? (That only returns the user who started the current process which is an IIS account, not the logged in user.)

Any help? I'd really appreciate it.

David Garner
 
Old July 17th, 2003, 01:46 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 158
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to NotNowJohn
Default

Code:
using System.Security.Principal;
...
WindowsIdentity MyIdentity = WindowsIdentity.GetCurrent();
WindowsPrincipal MyPrincipal = new WindowsPrincipal(MyIdentity);
string userName = MyPrincipal.Identity.Name;
...but the Soon is eclipsed by the Moon
 
Old July 17th, 2003, 02:23 PM
Registered User
 
Join Date: Jul 2003
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks NotNowJohn.

That doesn't quite do it. This is an intranet application. Not a windows form. The site is already secured and only company users can get in. They will all be on Windows Platform so they will all have a Windows Login.

The System.Security.Principal classes return the login name of the server running the app. Not the end user.

Your suggestion works for a windows form, but not a web application.

I may have to go with my second plan of attack and have the users enter their login criteria again (I had hoped to avoid that) and then look up their statistics in the Active Directory.

Any other suggestions? Anyone?

David Garner
 
Old July 17th, 2003, 03:34 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 158
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to NotNowJohn
Default

Have you configured your app to use Windows Authentication in Web.config file?

...but the Soon is eclipsed by the Moon
 
Old July 17th, 2003, 04:07 PM
Registered User
 
Join Date: Jul 2003
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes, but now I turned off impersonation and that did the trick.

I also used HttpContext.Current.User to return an IWindowsPrincipal object instead.

Thanks for pointing me in the right direction. Without your help I'd still be mucking around with DirectoryEntries and Environment variables.

David Garner





Similar Threads
Thread Thread Starter Forum Replies Last Post
Determine if user is accessing through Internet or dreamer_0244 Visual Studio 2005 5 December 10th, 2007 10:45 AM
Need urgent help loading user controls at runtime rpeters83 ASP.NET 2.0 Professional 7 September 3rd, 2006 10:17 AM
Retreiving user interface parameter at runtime saeedahmed C# 0 November 7th, 2005 02:53 AM
Load User Controls at Runtime Duncan VB.NET 3 November 4th, 2005 07:05 PM
Determine OS adman Beginning VB 6 2 January 5th, 2004 02:26 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.