Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AUTH_USER is returning blank when using in MVC4

Tags:

I remember, that I used to get Logged In user ID(for Intranet Application) using the following code:-

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

It still works fine when I use it in code behind of ASP application. But when I am using the same code in MVC4 Application it is returning me blank.

I am running my project as Use Local IIS Web Server and my web.config I have-

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

Please let me know, If I am doing some thing silly.

like image 447
Shubh Avatar asked Sep 17 '13 11:09

Shubh


1 Answers

I was missing some configuration, I created a New MVC Intranet Application and did the setting changes as follows:-

Hosting on IIS Express:

  1. Click on your project in the Solution Explorer to select the project.
  2. If the Properties pane is not open, open it (F4).
  3. In the Properties pane for your project:

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

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

Hosting on IIS 7 or later:

  1. Open IIS Manager and navigate to your website.
  2. In Features View, double-click Authentication.
  3. On the Authentication page, select Windows authentication. If Windows authentication is not an option, you'll need to make sure Windows authentication is installed on the server.

    To enable Windows authentication on Windows:

    a) In Control Panel open "Programs and Features".

    b) Select "Turn Windows features on or off".

    c) Navigate to Internet Information Services > World Wide Web Services > Security and make sure the Windows authentication node is checked.

    To enable Windows authentication on Windows Server:

    a) In Server Manager, select Web Server (IIS) and click Add Role Services.

    b) Navigate to Web Server > Security and make sure the Windows authentication node is checked.

  4. In the Actions pane, click Enable to use Windows authentication.

  5. On the Authentication page, select Anonymous authentication.
  6. In the Actions pane, click Disable to disable anonymous authentication.

Source:- readme.txt of MVC Intranet Application

like image 58
Shubh Avatar answered Sep 24 '22 02:09

Shubh