Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I'm in an intranet/Windows domain setup on Windows 2003 and IIS6 coding an ASP.Net 1.1 Intranet application.

 

I need to retrieve the currnet web viewer's username (as authorized by the domain) but cannot seem to retrieve it anywhere. I notice products like MS Sharpeoint 2003 knows the username with a user typing it in. How can I get the username, I have tried the following ways below and as you can see, I always end up getting the username the ASP.Net is running as.

 

System.Security.Principal.WindowsIdentity.GetCurrent().Name: NT AUTHORITY\NETWORK SERVICE

System.Threading.Thread.CurrentPrincipal.Identity.Name:

System.Threading.Thread.CurrentThread.Name:

System.Windows.Forms.SystemInformation.UserName: NETWORK SERVICE

Experience is something you don't get until just after the moment you needed it
Posted

Here is an answer

 

You'll have to refuse anonymous login to your app. And activate Domain Login by Basic or Digest (or anything...)

 

And activate Integrated Security. After that :

 

ntlogin = HttpContext.Current.User.Identity.Name; //Format : DOMAIN\USERNAME
ntlogin = zcntlogin.Substring( zcntlogin.IndexOf(@"\")+1);//FORMAT : USERNAME

ntlogin = HttpContext.Current.User.Identity.Name 'Format : DOMAIN\USERNAME
ntlogin = zcntlogin.Substring((zcntlogin.IndexOf("\") + 1)) 'Format: USERNAME

"If someone say : "Die mortal !"... don't stay to see if he isn't." - Unknown

"Learning to program is like going out with a new girl friend. There's always something that wasn't mentioned in the documentation..." - Me

"A drunk girl is like an animal... it scream at everything like a cat and roll in the grass like a dog." - Me after seeing my girlfriend drunk and some of her drunk friend.

C# TO VB TRANSLATOR

Posted

using System.Security.Principal;

Response.Write("User.Identity.Name: "+ User.Identity.Name);

 

User.Identity.Name:

 

I get nothing in return.

Experience is something you don't get until just after the moment you needed it
Posted

I GOT IT!

Ok I figured out why I never got the real username. I had to manage IIS, right click Web sites > Properties > Directory Security > Auth & Access Control EDIT

and then uncheck "enable anonymous acces"

 

I assumed IIS6 went from most secure to least secure ways to authorize, and figured anon would be last. It seems I was almast right, but anon comes first.

 

I can get the username in these parts of the framework:

User.Identity.Name

HttpContext.Current.User.Identity.Name

System.Threading.Thread.CurrentPrincipal.Identity.Name

 

And will be using the 1st or 2nd.

Experience is something you don't get until just after the moment you needed it
Posted

PlausiblyDamp,

 

it seems you were on to my problem, although you posted your question just 2 minutes after I figured it out. Big thanks for trying to help, this is something that has been nagging me for 2 weeks and I've just been working around it. This post helped me 'get in the mood' for try all sorts of things.

Experience is something you don't get until just after the moment you needed it
Posted

LOL

 

Exactly... but hey... who listen to my post ? :p

 

They are too lazy to scroll down :p lollll

 

Anyway... the answer is there... I can only show you the door. You'll have to open it yourself. :p (Quote from : Morpheus)

"If someone say : "Die mortal !"... don't stay to see if he isn't." - Unknown

"Learning to program is like going out with a new girl friend. There's always something that wasn't mentioned in the documentation..." - Me

"A drunk girl is like an animal... it scream at everything like a cat and roll in the grass like a dog." - Me after seeing my girlfriend drunk and some of her drunk friend.

C# TO VB TRANSLATOR

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...