title: MVC6 Prevent Redirect on unauthorized
body: <p>I'm developing an ASP.NET MVC 6 Web API app, with AngularJs frontend.</p>
  
  <p>When I leave a session to decade, or I'm trying to call a Web API action unauthorized, I expect to receive a 401 status code.
  Instead, I get a 302, and tries to redirect to the default path for login ("/Account/Login").</p>
  
  <p>So I need to handle this in Angular.</p>
  
  <p>From other forum posts here and googling I found that some people resolved their problems using in startup.cs:</p>
  
  <pre><code>services.Configure&lt;CookieAuthenticationOptions&gt;(options =&gt;
   {
       options.LoginPath = PathString.Empty;
  });
  </code></pre>
  
  <p>No luck for me.</p>
  
  <p>I use Identity as authentication backend and even adding</p>
  
  <pre><code>services.ConfigureIdentityApplicationCookie(options =&gt;
  {
       options.LoginPath = PathString.Empty;
  });
  </code></pre>
  
  <p>does not give me the expected result. ASP.NET docs suggest this way to return a 401.</p>
  
  <p>Using 1.0.0-beta7 CLR x86, IIS Express.</p>