1

Below is the web.config

<authentication mode="Windows" />
    <authorization>
            <allow users="*"/>
            <deny users="?" />
    </authorization>

But when I debug in visual studio, the HttpContext.Current.User.IsAuthenticated is false and the HttpContext.Current.User.Identity.Name remains empty

Why this happen?


When I change the web.config to this, a 401 error shows...

 <authorization>

      <deny users="?" />
    </authorization>
User2012384
  • 4,769
  • 16
  • 70
  • 106
  • The answer may vary, but check out [this post](http://stackoverflow.com/questions/1571036/httpcontext-current-user-identity-name-is-empty?rq=1). It's got some great resources. – Nick Jan 24 '14 at 01:52
  • @NicholasV. Please take a look at my edit, just now disabled anonymous access in web.config but an unauthorized access error shows.. – User2012384 Jan 24 '14 at 02:05

3 Answers3

4

Just now solved the problem by changing "Use Local IIS Web server to "Use Visual Studio Development Server in the "Properties" page enter image description here

User2012384
  • 4,769
  • 16
  • 70
  • 106
1

Your configuration allows anonymous users. You'll only get usernames for authenticated users.

<authorization>
    <!-- Deny anonymous users -->
    <deny users="?" />

    <!-- Allow everyone else (authenticated users) -->
    <allow users="*" />
</authorization>

Make sure that you have the Windows Authentication component installed and activated in IIS.

enter image description here enter image description here

sisve
  • 19,501
  • 3
  • 53
  • 95
0

Since as of Visual Studio 2013 "Visual Studio Development Server" is no longer available, we will need to choose IIS Express and make sure we have enabled windows authentication in the applicationhost.config file

<windowsAuthentication enabled="true">

Besides of configuring our IIS Express as @sisve's answer describes.

Jamo
  • 494
  • 5
  • 24