travisowens Posted July 18, 2005 Posted July 18, 2005 I have an Intranet ASP.Net app that retrieves the current visitors Active Directory username via HttpContext.Current.User.Identity.Name which works fine locally (after setting Directory Security on the folder, of course, also set on the test server) and for other users it works fine on my test server but when I view the webapp on the test server the app always returns the local admin account (ex: servername/Administrator) instead of my AD username (ex: domain/JDoe). How do I force the AD credentials take precedence over the server local credentials? Quote Experience is something you don't get until just after the moment you needed it
samsmithnz Posted July 19, 2005 Posted July 19, 2005 1. Is the server on the same domain as your active directory server? 2. Have you made sure that the Windows Authentication box is checked in your projects IIS settings? Quote Thanks Sam http://www.samsmith.co.nz
travisowens Posted July 19, 2005 Author Posted July 19, 2005 1. Is the server on the same domain as your active directory server? 2. Have you made sure that the Windows Authentication box is checked in your projects IIS settings? 1. Yes 2. Yes Quote Experience is something you don't get until just after the moment you needed it
mperillo Posted July 20, 2005 Posted July 20, 2005 Would you be able to post your original code that you're obtaining the AD Username locally? Quote
bri189a Posted July 21, 2005 Posted July 21, 2005 You didn't mention it so.... And you have windows authentication in the web.config file? Quote
travisowens Posted July 21, 2005 Author Posted July 21, 2005 UCommonASP.cs contains... using System; using System.Web; namespace UCommon { public class ASP { public static string CurrentASPUserName() { string username = HttpContext.Current.User.Identity.Name; if (username != "" && username != null) { // this returns the format of "domain/username" so we must split it string[] userinfo = HttpContext.Current.User.Identity.Name.Split(Convert.ToChar("\\")); // the username will always be the 2nd item in the array return userinfo[1]; } else { return "Unknown"; } } } } Web.config contains <authentication mode="Windows" /> FYI I get the same result for the username despite if I use a seperate class or if I do it within my code. In my app I do the following Response.Write("<!-- Class UserName='" + UCommon.ASP.CurrentASPUserName() + "' -->\n"); Response.Write("<!-- Local UserName='" + HttpContext.Current.User.Identity.Name + "' -->\n"); Which prints out the following when access this app on the server from my PC, please note it says this ONLY on my PC, if I log into any other PC I get my proper Active Directory username. Please note my CurrentASPUserName() splits the domain & username before returning it. <!-- Class UserName='Administrator' --> <!-- Local UserName='DEVGRPQA\Administrator' --> When I run the app locally via VS or access it from another PC to the server I see: <!-- Class UserName='towens' --> <!-- Local UserName='UNITY_HS\towens' --> The app works fine for everybody else, and my desktop IS joined to the domain and I'm logged into the domain also. Quote Experience is something you don't get until just after the moment you needed it
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.