Search code examples
asp.netasp.net-mvcasp.net-web-apiwindows-authentication

Why isn't Integrated Windows Authentication working?


I created a new ASP.NET MVC application with the Web API template. I selected the authentication mode as "Windows Authentication" while creating the project.

I added windows authentication in the web.config:

  <system.web>
    <authentication mode="Windows" />
  </system.web>

I made sure that Windows Authentication was installed on IIS and enabled in the same web application in IIS.

I created a controller action that displays the user's username:

public JsonResult Login()
{
    string userName = System.Web.HttpContext.Current.User.Identity.Name;
    string message = String.Format("Welcome, {0}!", userName);
    return Json(userName, JsonRequestBehavior.AllowGet);
}

When I access this URL in the browser, the user is not prompted for the credentials and the returned value is an empty string.

What am I missing?


Solution

  • You have to deactivate Anonymous Authentication and activate Windows Authentication for your site in the IIS management console.