2

I have done a bunch of research about this, but can't find a solution to this problem.

my web.config :

  <system.web>
    <compilation debug="true" targetFramework="4.5.1"/>
    <httpRuntime targetFramework="4.5.2"/>
    <authentication mode="Windows"/>
    <authorization>
      <deny users="?"/>
    </authorization>
  </system.web>

and for some reason

string User = User.Identity.Name;

is always blank.

IIS Windows authentication is the only option that is enabled.

i have tried the

[Authorize]

same result.

I checked the IIS config file to make sure

  <windowsAuthentication enabled="true">

is set to true.

Birby
  • 331
  • 1
  • 3
  • 8

1 Answers1

3

Are you working within an authorized context? In other words, unless you actually say you want a particular controller or action authorized, nothing is filled even if the user has previously logged in. For example:

public ActionResult Foo()
{
    var user = User.Identity.Name; // null
}

But

[Authorize]
public ActionResult Foo()
{
   var user = User.Identity.Name; // WIN
}

If you need the action to still allow anonymous access, just add [AllowAnonymous] as well:

[Authorize]
[AllowAnonymous]
public ActionResult Foo()
{
    ...
Chris Pratt
  • 207,690
  • 31
  • 326
  • 382