Last post Jan 06, 2017 05:40 PM by xd40_Man
Jan 06, 2017 03:11 PM|XD40_Man|LINK
I'm using this to grab the LDAP user and print it to a section of the page:
public static string GetUserFullName(string domain, string userName)
DirectoryEntry userEntry = new DirectoryEntry("WinNT://" + domain + "/" + userName + ",User");
Then I call the function like this:
<b>Current User: @CB.App_Data.LDAP.GetUserFullName(Environment.UserDomainName, Environment.UserName)</b>
This all works JUST fine on my local machine. But, when I deploy the code to my IIS box the name shows the actual server's name.
So, I have a server called "it-myserver". When I run the app from the server it shows "it-myserver" instead of showing my name "John Doe".
Any ideas as to why this is happening?
Jan 06, 2017 03:58 PM|PatriceSc|LINK
Environment.UserName is the name of the account under which the server side code runs. So usually it "works" on a development machine and on a web server it depends on which settings are configured for this particular point. So use that only if you want
to know which account is running your code.
To know which user is logged to your web site, use User.Identity.Name instead (it is exposed by MVC controllers, Web Forms pages or using System.Web.HttpContext.Current). Also it works regardless of which authentication method is used.
Jan 06, 2017 05:40 PM|XD40_Man|LINK
Thank you so much!!!