travisowens Posted August 17, 2004 Posted August 17, 2004 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 Quote Experience is something you don't get until just after the moment you needed it
Administrators PlausiblyDamp Posted August 17, 2004 Administrators Posted August 17, 2004 From within the ASP.Net application itself you should be able to use the user class to find out this info label1.text = user.Identity.Name label2.text = user.IsInRole("DOMAIN\Users") Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Arch4ngel Posted August 17, 2004 Posted August 17, 2004 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 : USERNAMEntlogin = HttpContext.Current.User.Identity.Name 'Format : DOMAIN\USERNAME ntlogin = zcntlogin.Substring((zcntlogin.IndexOf("\") + 1)) 'Format: USERNAME Quote "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
travisowens Posted August 17, 2004 Author Posted August 17, 2004 using System.Security.Principal; Response.Write("User.Identity.Name: "+ User.Identity.Name); User.Identity.Name: I get nothing in return. Quote Experience is something you don't get until just after the moment you needed it
travisowens Posted August 17, 2004 Author Posted August 17, 2004 I get nothing when I try to access HttpContext.Current.User.Identity.Name Quote Experience is something you don't get until just after the moment you needed it
travisowens Posted August 17, 2004 Author Posted August 17, 2004 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. Quote Experience is something you don't get until just after the moment you needed it
Administrators PlausiblyDamp Posted August 17, 2004 Administrators Posted August 17, 2004 Do you allow anonymous access via IIS? Also in your web.config what authentication settings are you using? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
travisowens Posted August 17, 2004 Author Posted August 17, 2004 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. Quote Experience is something you don't get until just after the moment you needed it
VBAHole22 Posted August 17, 2004 Posted August 17, 2004 You'll have to refuse anonymous login to your app I think Arch4ngel was trying to tell you that. Quote Wanna-Be C# Superstar
Arch4ngel Posted August 17, 2004 Posted August 17, 2004 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) Quote "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
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.