2

It works locally but when I upload my website to an IIS server then it wont work: this is part of my config file which I thought it would work:

<authentication mode="Windows">
</authentication>
<identity impersonate="true"/>
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
</system.webServer>

My asp.net code which works locally but not on server:

 string[] temp = Convert.ToString(System.Security.Principal.WindowsIdentity.GetCurrent().Name).Split('\\');
 string userName = temp[1] + "@" + temp[0];
 Console.WriteLine("name: "+ userName);

The name/error which is saved is

NT AUTHORITY\IUSR

Im using windows server 2012 version 6.2 How can I get the windows users name?

4
  • Im sorry, but I think it's working, isn't it the IUSR which is connected with the IIS instance? I think it is. Take a look here: learn.microsoft.com/en-us/iis/get-started/planning-for-security/… Commented Feb 16, 2018 at 14:03
  • Hi It's working yes, but I can't get the machine name/ windows name? if different users use the page? Commented Feb 16, 2018 at 14:06
  • 2
    As far as I know you can't get the machine name of the visiting machine, unless your on the same internal network and you are able to resolve the name of the computer. On the internet the best you can get is the ip and/or the dns name of the user provided from the ISP. Commented Feb 16, 2018 at 14:09
  • Thank you very much, I will look into that :-) Commented Feb 16, 2018 at 14:14

2 Answers 2

0

It looks like you still have anonymous authentication enabled. Make sure, that it is disabled and only windows authentication is enabled.

A second approach to retrieve the account name of the current user is: Request.LogonUserIdentity.Name

enter image description here

Sign up to request clarification or add additional context in comments.

2 Comments

When I do this, the whole server goes down and shows an error 500. There is now Windows Authentication on the list either
What do you mean by "There is now Windows Authentication on the list either"? Now or no? If windows authentication is missing you need to add the feature to the IIS. However, you need to deactivate anonymous authentication and activate windows authentication (or any other authentication type depending on the type of account you'd like to identify)
0

You may be using the wrong property. What you are using will return the username of the account that is running IIS. So on your machine it will be your account if you are running IIS Express for example and will be the service account that the AppPool is running under if it is on a deployed IIS server.

To get the account name of the actual user/machine connecting the you should use

string[] temx = Convert.ToString(HttpContext.Request.LogonUserIdentity.Name).Split('\\');

That is assuming you have anonymous turned off and are using some kind of authentication.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.