AUTH_USER returns empty when used in MVC4

I remember what I used to enter the user ID (for the Intranet application) using the following code: -

string WindowsLoginID= System.Web.HttpContext.Current.Request.ServerVariables["AUTH_USER"];// This is blank 

It still works great when I use it in code behind an ASP application. But when I use the same code in MVC4 Application , it returns me blank .

I run my project as Use Local IIS Web Server , and my web.config is mine

 <authentication mode="Windows"> </authentication> 

Please let me know if I am doing something stupid.

+4
source share
2 answers

I was missing any configuration, I created the New MVC Intranet application and changed the settings as follows: -

Hosting on IIS Express:

  • Select a project in Solution Explorer to select a project.
  • If the Properties panel is not open, open it (F4).
  • In the Properties panel for your project:

    a) Set Anonymous Authentication to Disabled.

    b) Set Windows Authentication to Enabled.

Hosting on IIS 7 or later:

  • Open IIS Manager and go to your website.
  • In the Features view, double-click Authentication.
  • On the Authentication page, select Windows Authentication. If Windows authentication is not an option, you need to make sure that Windows authentication is installed on the server.

    To enable Windows authentication on Windows:

    a) On the control panel, open "Programs and Features."

    b) Select "Turn Windows Features On or Off."

    c) Go to Internet Information Services> World Wide Web Services> Security and verify that Windows node authentication is verified.

    To enable Windows authentication on Windows Server:

    a) In Server Manager, select the web server (IIS) and click Add Role Services.

    b) Go to web server> Security and make sure Windows node authentication is verified.

  • In the Actions panel, click Enable to use Windows Authentication.

  • On the Authentication page, select Anonymous Authentication.
  • In the Actions panel, click Disable to disable anonymous authentication.

Source: - readme.txt MVC Intranet application

+7
source

In the Properties pane for your project:

a) Set "Anonymous Authentication" to "Disabled".

b) Set "Windows Authentication" to "Enabled".

Hope this helps!

+5
source

Source: https://habr.com/ru/post/1502583/