2

I am facing the problem where User.Identity.Name coming back empty ONLY on my local Visual Studio Environment. When the site is published on IIS, it works all fine and gets the correct user.

I searched for the problem online but it looks like most of the solution suggested are suggested for IIS environment and asking to change the config file. My config file looks as following:

<system.web>
    <compilation debug="true" targetFramework="4.6" />
    <httpRuntime targetFramework="4.6" />
    <customErrors mode="Off" />
    <authentication mode="Windows" />
    <!--<authorization>
      <allow roles="IS APPS" />
      <deny users="?" />
    </authorization>-->

  </system.web>

I had to comment out the part where it does because if I turn it on, I run into 401.2 HTTpError

Lost
  • 12,007
  • 32
  • 121
  • 193

2 Answers2

2

An option to solve the problem, you have to enable the Windows Authentication feature on your machine (had the same issue once):

  • Click Start, and then click Control Panel.
  • Open the Programs group.
  • Under Programs and -Features, click Turn Windows Features on or off.
  • Expand the item labeled Internet Information Services.
  • Expand the item labeled World Wide Web Services.
  • Expand the item Security -> Make sure to select Windows Authentication

Alternative: May be just a config issue then:

<authentication mode="Windows">
    <anonymousAuthentication enabled="false" userName="" />
</authentication>
Jelle Oosterbosch
  • 1,731
  • 15
  • 17
  • I turned it on and restarted my PC but it did not work. Also, my project is not mapped to local IIS. Its running on VS Dev server as default. – Lost Oct 23 '15 at 16:53
1

Here is the answer that I found from another SO POST. Not sure why this was not marked as the answer on that POST:

Authentication issue when debugging in VS2013 - iis express

Answer:

In Visual Studio 2013 just press F4 and change this two properties Anonymous Authentication: Disable Windows Authentication: Enable

Community
  • 1
  • 1
Lost
  • 12,007
  • 32
  • 121
  • 193