title: MVC5 Redirects to Login.aspx when using Windows Authentication
body: <p>After upgrading from MVC 4 to MVC 5, my application (when started from within Visual Studio) gives the following error. It might also be worth noting that I am hosting both MVC5 and WebAPI2 items in the same project as there may be interference going on. I also installed the dotnetopenauth nuget package (which I have since removed):</p>
  
  <pre><code>Server Error in '/' Application.
  
  The resource cannot be found.
  
  Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable.  Please review the following URL and make sure that it is spelled correctly. 
  
  Requested URL: /login.aspx
  </code></pre>
  
  <p>I'm not really sure why this is as there is no authorization attributes set in the filters or on the controllers.</p>
  
  <p>Global.asax:</p>
  
  <pre><code>    public class MvcApplication : HttpApplication {
  
      protected void Application_Start() {
          IDependencyInjectionBuilder dependencyInjectionBuilder = new DependencyInjectorBuilder();
          var builder = new ContainerBuilder();
  
          builder.RegisterControllers(typeof(MvcApplication).Assembly);
          builder.RegisterApiControllers(Assembly.GetExecutingAssembly()); //For WebAPI dependency injection
          var injector = new AutofacDependencyInjector();
          dependencyInjectionBuilder.RegisterTypesAndInstances(injector, false, true);
          DependencyInjectionRegistration.RegisterServices(injector);
  
          builder.Update(injector.Container.ComponentRegistry);
  
          var autofacDependencyResolver = new AutofacDependencyResolver(injector.Container);
          DependencyResolver.SetResolver(autofacDependencyResolver);
  
          GlobalConfiguration.Configuration.DependencyResolver = new AutofacWebApiDependencyResolver(injector.Container); //For WebAPI dependency injection
  
          AreaRegistration.RegisterAllAreas();
  
          AutoMapperConfig.RegisterMappings(Mapper.Configuration);
  
          //Reference: http://www.asp.net/mvc/tutorials/mvc-5/how-to-upgrade-an-aspnet-mvc-4-and-web-api-project-to-aspnet-mvc-5-and-web-api-2
          GlobalConfiguration.Configure(WebApiConfig.Register);
  
          FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
          RouteConfig.RegisterRoutes(RouteTable.Routes);
          BundleConfig.RegisterBundles(BundleTable.Bundles);
  
          GlobalConfiguration.Configuration.EnsureInitialized();
  
  #if DEBUG
          // Uncomment this line for the nhibernate profiler 
          // and add HibernatingRhinos.Profiler.Appender.dll
          // to the PD.UserInterfacePbj project references
  
         //HibernatingRhinos.Profiler.Appender.NHibernate.NHibernateProfiler.Initialize();
  #endif
      }
  }
  </code></pre>
  
  <p>Root Web.config:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;configuration&gt;
    &lt;configSections&gt;
      &lt;section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate" /&gt;
      &lt;section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" /&gt;
      &lt;/configSections&gt;
      &lt;appSettings&gt;
          &lt;add key="webpages:Version" value="3.0.0.0" /&gt;
          &lt;add key="webpages:Enabled" value="false" /&gt;
          &lt;add key="PreserveLoginUrl" value="true" /&gt;
          &lt;add key="ClientValidationEnabled" value="true" /&gt;
          &lt;add key="UnobtrusiveJavaScriptEnabled" value="true" /&gt;
      &lt;/appSettings&gt;
      &lt;log4net&gt;
          &lt;appender name="NHProfAppender" type="HibernatingRhinos.Profiler.Appender.NHibernate.NHProfAppender, HibernatingRhinos.Profiler.Appender.NHibernateLog4Net"&gt;
              &lt;sink value="tcp://127.0.0.1:56107" /&gt;
          &lt;/appender&gt;
          &lt;logger name="HibernatingRhinos.Profiler.Appender.NHibernate.NHProfAppender.Setup"&gt;
              &lt;appender-ref ref="NHProfAppender" /&gt;
          &lt;/logger&gt;
          &lt;root&gt;
              &lt;priority value="ALL" /&gt;
              &lt;appender-ref ref="ConsoleAppender" /&gt;
          &lt;/root&gt;
      &lt;/log4net&gt;
      &lt;system.web&gt;
          &lt;customErrors mode="Off" defaultRedirect="~/Error/Index"&gt;
              &lt;error statusCode="404" redirect="~/Error/Error404" /&gt;
          &lt;/customErrors&gt;
          &lt;compilation debug="true" targetFramework="4.5" /&gt;
          &lt;httpRuntime /&gt;
          &lt;authentication mode="Windows" /&gt;
          &lt;authorization&gt;
              &lt;deny users="?" /&gt;
          &lt;/authorization&gt;
          &lt;pages controlRenderingCompatibilityVersion="4.0"&gt;
              &lt;namespaces&gt;
                  &lt;add namespace="System.Web.Helpers" /&gt;
                  &lt;add namespace="System.Web.Mvc" /&gt;
                  &lt;add namespace="System.Web.Mvc.Ajax" /&gt;
                  &lt;add namespace="System.Web.Mvc.Html" /&gt;
                  &lt;add namespace="System.Web.Optimization" /&gt;
                  &lt;add namespace="System.Web.Routing" /&gt;
                  &lt;add namespace="System.Web.WebPages" /&gt;
                  &lt;add namespace="My.Localization" /&gt;
              &lt;/namespaces&gt;
          &lt;/pages&gt;
      &lt;/system.web&gt;
      &lt;system.webServer&gt;
          &lt;modules runAllManagedModulesForAllRequests="true" /&gt;
          &lt;validation validateIntegratedModeConfiguration="false" /&gt;
          &lt;handlers&gt;
              &lt;remove name="ExtensionlessUrlHandler-Integrated-4.0" /&gt;
              &lt;remove name="OPTIONSVerbHandler" /&gt;
              &lt;remove name="TRACEVerbHandler" /&gt;
              &lt;add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" /&gt;
          &lt;/handlers&gt;
      &lt;/system.webServer&gt;
      &lt;runtime&gt;
          &lt;assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"&gt;
              &lt;dependentAssembly&gt;
                  &lt;assemblyIdentity name="System.Web.WebPages.Razor" publicKeyToken="31bf3856ad364e35" /&gt;
                      &lt;bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" /&gt;
              &lt;/dependentAssembly&gt;
              &lt;dependentAssembly&gt;
                  &lt;assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" /&gt;
                  &lt;bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" /&gt;
              &lt;/dependentAssembly&gt;
              &lt;dependentAssembly&gt;
                  &lt;assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" /&gt;
                  &lt;bindingRedirect oldVersion="1.0.0.0-5.0.0.0" newVersion="5.0.0.0" /&gt;
              &lt;/dependentAssembly&gt;
              &lt;dependentAssembly&gt;
                  &lt;assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" /&gt;
                  &lt;bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" /&gt;
              &lt;/dependentAssembly&gt;
              &lt;dependentAssembly&gt;
                  &lt;assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" /&gt;
                  &lt;bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" /&gt;
              &lt;/dependentAssembly&gt;
              &lt;dependentAssembly&gt;
                  &lt;assemblyIdentity name="Microsoft.Data.OData" publicKeyToken="31bf3856ad364e35" culture="neutral" /&gt;
                  &lt;bindingRedirect oldVersion="0.0.0.0-5.5.0.0" newVersion="5.5.0.0" /&gt;
              &lt;/dependentAssembly&gt;
              &lt;dependentAssembly&gt;
                  &lt;assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" culture="neutral" /&gt;
                  &lt;bindingRedirect oldVersion="0.0.0.0-4.5.0.0" newVersion="5.0.0.0" /&gt;
              &lt;/dependentAssembly&gt;
              &lt;dependentAssembly&gt;
                  &lt;assemblyIdentity name="Microsoft.Data.Edm" publicKeyToken="31bf3856ad364e35" culture="neutral" /&gt;
                  &lt;bindingRedirect oldVersion="0.0.0.0-5.5.0.0" newVersion="5.5.0.0" /&gt;
              &lt;/dependentAssembly&gt;
              &lt;dependentAssembly&gt;
                  &lt;assemblyIdentity name="System.Spatial" publicKeyToken="31bf3856ad364e35" culture="neutral" /&gt;
                  &lt;bindingRedirect oldVersion="0.0.0.0-5.5.0.0" newVersion="5.5.0.0" /&gt;
              &lt;/dependentAssembly&gt;
              &lt;dependentAssembly&gt;
                  &lt;assemblyIdentity name="NHibernate" publicKeyToken="aa95f207798dfdb4" culture="neutral" /&gt;
                  &lt;bindingRedirect oldVersion="0.0.0.0-3.3.1.4000" newVersion="3.3.1.4000" /&gt;
              &lt;/dependentAssembly&gt;
              &lt;dependentAssembly&gt;
                  &lt;assemblyIdentity name="Antlr3.Runtime" publicKeyToken="eb42632606e9261f" culture="neutral" /&gt;
                  &lt;bindingRedirect oldVersion="0.0.0.0-3.5.0.2" newVersion="3.5.0.2" /&gt;
              &lt;/dependentAssembly&gt;
          &lt;/assemblyBinding&gt;
      &lt;/runtime&gt;
      &lt;hibernate-configuration xmlns="urn:nhibernate-configuration-2.2"&gt;
          &lt;bytecode-provider type="null" /&gt;
          &lt;!-- Important under Medium Trust --&gt;
          &lt;session-factory name="Stinky Pete"&gt;
              &lt;property name="connection.provider"&gt;NHibernate.Connection.DriverConnectionProvider&lt;/property&gt;
              &lt;property name="dialect"&gt;NHibernate.Dialect.MsSql2008Dialect&lt;/property&gt;
              &lt;property name="connection.driver_class"&gt;NHibernate.Driver.SqlClientDriver&lt;/property&gt;
              &lt;property name="connection.connection_string"&gt; ... &lt;/property&gt;
              &lt;mapping assembly=" ... " /&gt;
          &lt;/session-factory&gt;
      &lt;/hibernate-configuration&gt;
      &lt;system.net&gt;
          &lt;defaultProxy enabled="true" /&gt;
          &lt;settings&gt;
          &lt;!--&lt;servicePointManager checkCertificateRevocationList="true"/&gt;--&gt;
          &lt;/settings&gt;
      &lt;/system.net&gt;
      &lt;uri&gt;
          &lt;!-- The uri section is necessary to turn on .NET 3.5 support for IDN (international domain names), which is necessary for OpenID urls with unicode characters in the domain/host name. 
      It is also required to put the Uri class into RFC 3986 escaping mode, which OpenID and OAuth require. --&gt;
          &lt;idn enabled="All" /&gt;
          &lt;iriParsing enabled="true" /&gt;
      &lt;/uri&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>Views Web.config:</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;configuration&gt;
      &lt;configSections&gt;
          &lt;sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"&gt;
              &lt;section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" /&gt;
              &lt;section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" /&gt;
          &lt;/sectionGroup&gt;
      &lt;/configSections&gt;
      &lt;system.web.webPages.razor&gt;
          &lt;host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /&gt;
          &lt;pages pageBaseType="System.Web.Mvc.WebViewPage"&gt;
              &lt;namespaces&gt;
                  &lt;add namespace="System.Web.Mvc" /&gt;
                  &lt;add namespace="System.Web.Mvc.Ajax" /&gt;
                  &lt;add namespace="System.Web.Mvc.Html" /&gt;
                  &lt;add namespace="System.Web.Optimization"/&gt;
                  &lt;add namespace="System.Web.Routing" /&gt;
                  &lt;add namespace="Infragistics.Web.Mvc"/&gt;
              &lt;/namespaces&gt;
          &lt;/pages&gt;
      &lt;/system.web.webPages.razor&gt;
      &lt;appSettings&gt;
          &lt;add key="webpages:Enabled" value="false" /&gt;
      &lt;/appSettings&gt;
      &lt;system.web&gt;
          &lt;httpHandlers&gt;
              &lt;add path="*" verb="*" type="System.Web.HttpNotFoundHandler"/&gt;
          &lt;/httpHandlers&gt;
          &lt;pages validateRequest="false" pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=5.0.0.0,  Culture=neutral, PublicKeyToken=31BF3856AD364E35" pageBaseType="System.Web.Mvc.ViewPage,  System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=5.0.0.0,  Culture=neutral, PublicKeyToken=31BF3856AD364E35"&gt;
              &lt;controls&gt;
                  &lt;add assembly="System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc" /&gt;
              &lt;/controls&gt;
          &lt;/pages&gt;
      &lt;/system.web&gt;
      &lt;system.webServer&gt;
          &lt;validation validateIntegratedModeConfiguration="false" /&gt;
          &lt;handlers&gt;
              &lt;remove name="BlockViewHandler"/&gt;
              &lt;add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" /&gt;
          &lt;/handlers&gt;
      &lt;/system.webServer&gt;
  &lt;/configuration&gt;
  </code></pre>