title: MVC5 app not working in IIS 7 - Error 404 - File or directory not found
body: <p>there!  </p>
  
  <p>After some comings and goings, I finally got my very first MVC app working in my dev machine.  </p>
  
  <p>The scenario is as following: </p>
  
  <ul>
  <li>it's an intranet app (therefore I'm using Windows Authentication)</li>
  <li>it's a MVC 5 app (with Bootstrap and jQuery stuff - no .aspx pages)</li>
  <li>Entity Framework 6 (Code First)</li>
  <li>SQL Server Compact Edition</li>
  <li>VS 2013 Express Edition  </li>
  <li>Server: Windows 2008 R2, running IIS 7  </li>
  <li>Hotfix KB980368 installed  </li>
  <li>IIS registered with asp.net (command aspnet_regiis.exe -i ran)  </li>
  </ul>
  
  <p>I have some administrative rights on server, so I created a folder to hold the app. Then, using the VS2013, I published the app according to the following configuration:</p>
  
  <ul>
  <li>Publish method: File System</li>
  <li>Target location: the folder created on server</li>
  <li>Configuration: Release</li>
  <li>Databases: database publishing is not supported for this publish method</li>
  </ul>
  
  <p>The target on server was filled with the following folders: </p>
  
  <ul>
  <li>bin (System.Web.MVC, System.Web.Razor, etc )</li>
  <li>Content</li>
  <li>fonts</li>
  <li>Scripts</li>
  <li>Views</li>
  </ul>
  
  <p>and the following files:  </p>
  
  <ul>
  <li>Global.asax  </li>
  <li>packages.config  </li>
  <li>web.config  </li>
  </ul>
  
  <p>In IIS 7 I added a Virtual Directory with the Physical Path pointing to that folder previously created. After that I converted the virtual directory to Application.  </p>
  
  <p>Tried to run the app and got a weird startIndex error. Then I noticed the App_Data folder was not created. So i corrected that, re-run the app and by this time the databases were created and the default route was properly executed, rendering the main View.  </p>
  
  <p>All the views in the app are based upon this _Layout.cshtml, where there is a navbar with some navigating links and dropdown menus. One of these is a simple  element that links to the Contact View:  </p>
  
  <pre><code>&lt;a href="/Home/Contact"&gt;Contact&lt;/a&gt;
  </code></pre>
  
  <p>Well, when I click this element I get a <em>404 - File or directory not found</em> error. And so with all others links. I tried to explicitly write the route at the address bar of the browser and the Contact view was rendered. Of course, user is not supposed to know how to write the routes. For this we create the <em>navbars</em>, links and so on.  </p>
  
  <p>Then I began to <em>google</em> for this issue and since then I've read hundreds of articles, posts, pages ... On many of them it was mentioned that this issue would be simply solved adding a couple of lines on web.config, like <a href="https://stackoverflow.com/questions/12495346/asp-net-4-5-mvc-4-not-working-on-windows-server-2008-iis-7/16577694#16577694">this one</a>. I tried. Didn't work.  </p>
  
  <p>So, in IIS 7 the configuration is the following:</p>
  
  <ul>
  <li>Application Pool: <em>Framework</em>: v4.0.30319, <em>Managed Pipeline</em>: Integrated, <em>Identity</em>: ApplicationPoolApplication</li>
  <li>.NET Authorization Rules: Allow All Users</li>
  <li>.NET Trust Levels: Full (internal)</li>
  <li>Application Settings: <em>ClientValidationEnabled</em>: true, <em>UnobtrusiveJavaScriptEnabled</em>: true, <em>webpages:Enabled</em>: false, <em>webpages:Version</em>: 3.0.0.0</li>
  <li>Connection Strings: <em>DbControleDeAcesso</em>: Data Source=|DataDirectory|\ControleDeAcesso.sdf; <em>DbOrcamento</em>: Data Source=|Data Directory|\Orcamento.sdf</li>
  <li>Authentication: <em>Anonymous Authentication</em>: Disabled, <em>ASP.NET Impersonation</em>: Disabled, <em>Forms Authentication</em>: Disabled, <em>Windows Authentication</em>: Enabled</li>
  <li>Handler Mappings
  
  <ul>
  <li>ExtensiolessUrlHandler-Integrated-4.0
  
  <ul>
  <li>Path: *.</li>
  <li>State: Enabled</li>
  <li>Path Type: Unspecified</li>
  <li>Handler: System.Web.Handlers.TransferRequestHandler</li>
  <li>Entry Type: Local</li>
  </ul></li>
  <li>ExtensiolessUrlHandler-ISAP-4.0_32bit/64bit
  
  <ul>
  <li>Path: *.</li>
  <li>State: Enabled</li>
  <li>Path Type: Unspecified</li>
  <li>Handler: IsapiModule</li>
  <li>Entry Type: Inherited</li>
  </ul></li>
  </ul></li>
  <li>Modules
  
  <ul>
  <li>UrlRoutingModule-4.0
  
  <ul>
  <li>Code: System.Web.RoutingModule</li>
  <li>Module Type: Managed</li>
  <li>Entry Type: Local</li>
  </ul></li>
  </ul></li>
  </ul>
  
  <p>Bellow I present my <em>web.config</em> file:  </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;configuration&gt;
    &lt;configSections&gt;
      &lt;section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /&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="ClientValidationEnabled" value="true" /&gt;
      &lt;add key="UnobtrusiveJavaScriptEnabled" value="true" /&gt;
    &lt;/appSettings&gt;
    &lt;system.web&gt;
      &lt;compilation defaultLanguage="vb" targetFramework="4.5.1" /&gt;
      &lt;httpRuntime targetFramework="4.5.1" /&gt;
    &lt;/system.web&gt;
    &lt;runtime&gt;
      &lt;assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"&gt;
      &lt;dependentAssembly&gt;
        &lt;assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed" /&gt;
        &lt;bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" /&gt;
      &lt;/dependentAssembly&gt;
      &lt;dependentAssembly&gt;
        &lt;assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" /&gt;
        &lt;bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0" /&gt;
      &lt;/dependentAssembly&gt;
      &lt;dependentAssembly&gt;
        &lt;assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" /&gt;
        &lt;bindingRedirect oldVersion="1.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" /&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.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="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" /&gt;
        &lt;bindingRedirect oldVersion="1.0.0.0-5.2.2.0" newVersion="5.2.2.0" /&gt;
      &lt;/dependentAssembly&gt;
    &lt;/assemblyBinding&gt;
    &lt;/runtime&gt;
    &lt;entityFramework&gt;
      &lt;defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlCeConnectionFactory, EntityFramework"&gt;
        &lt;parameters&gt;
          &lt;parameter value="System.Data.SqlServerCe.4.0" /&gt;
        &lt;/parameters&gt;
      &lt;/defaultConnectionFactory&gt;
      &lt;providers&gt;
        &lt;provider invariantName="System.Data.SqlServerCe.4.0" type="System.Data.Entity.SqlServerCompact.SqlCeProviderServices, EntityFramework.SqlServerCompact" /&gt;
      &lt;/providers&gt;
    &lt;/entityFramework&gt;
    &lt;system.data&gt;
       &lt;DbProviderFactories&gt;
         &lt;remove invariant="System.Data.SqlServerCe.4.0" /&gt;
         &lt;add name="Microsoft SQL Server Compact Data Provider 4.0" invariant="System.Data.SqlServerCe.4.0" description=".NET Framework Data Provider for Microsoft SQL Server Compact" type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" /&gt;
       &lt;/DbProviderFactories&gt;
    &lt;/system.data&gt;
    &lt;connectionStrings&gt;
        &lt;remove name="LocalSqlServer" /&gt;
        &lt;add name="DbControleDeAcesso" providerName="System.Data.SqlServerCe.4.0" connectionString="Data Source=|DataDirectory|\ControleDeAcesso.sdf" /&gt;
        &lt;add name="DbOrcamento" providerName="System.Data.SqlServerCe.4.0" connectionString="Data Source=|DataDirectory|\Orcamento.sdf" /&gt;
    &lt;/connectionStrings&gt;
    &lt;system.webServer&gt;
       &lt;validation validateIntegratedModeConfiguration="false" /&gt;
       &lt;security&gt;
          &lt;authentication&gt;
              &lt;anonymousAuthentication enabled="false" /&gt;
              &lt;windowsAuthentication enabled="true" /&gt;
          &lt;/authentication&gt;
      &lt;/security&gt;
      &lt;modules runAllManagedModulesForAllRequests="true"&gt;
          &lt;remove name="UrlRoutingModule-4.0" /&gt;
          &lt;add name="UrlRoutingModule-4.0" type="System.Web.Routing.UrlRoutingModule" preCondition="" /&gt;
      &lt;/modules&gt;
      &lt;handlers&gt;
           &lt;remove name="ExtensionlessUrlHandler-Integrated-4.0" /&gt;
           &lt;add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" /&gt;
      &lt;/handlers&gt;
      &lt;defaultDocument&gt;
          &lt;files&gt;
              &lt;remove value="default.aspx" /&gt;
              &lt;remove value="iisstart.htm" /&gt;
              &lt;remove value="index.html" /&gt;
              &lt;remove value="index.htm" /&gt;
              &lt;remove value="Default.asp" /&gt;
              &lt;remove value="Default.htm" /&gt;
          &lt;/files&gt;
      &lt;/defaultDocument&gt;
      &lt;!-- &lt;handlers&gt;
          &lt;add name="UrlRoutingHandler" preCondition="integratedMode" verb="*" path="UrlRouting.axd" type="System.Web.HttpForbiddenHandler, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" /&gt;
      &lt;/handlers&gt; --&gt;
    &lt;/system.webServer&gt;
  &lt;/configuration&gt;  
  </code></pre>
  
  <p>I don't know whether it's relevant or not, but follows my <em>RouteConfig</em> class:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using System.Web.Mvc;
  using System.Web.Routing;
  
  namespace Orcamento.UI
  {
      public class RouteConfig
      {
          public static void RegisterRoutes(RouteCollection routes)
          {
              routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
  
              routes.MapRoute(
                  name: "Default",
                  url: "{controller}/{action}/{id}",
                  defaults: new { controller = "Orcamento", action = "Index", id = UrlParameter.Optional }
              );
          }
      }
  }  
  </code></pre>
  
  <p>I believe I've showed all the significant informations regarding my issue. If I've omitted any, please, just let me know.  </p>
  
  <p>I've invested a lot of time and effort to learn how to build a MVC app with EF, jQuery and so on. I got it working on my dev machine. I'm very frustrated that it's not working on production environment.  </p>
  
  <p>I'm really hopeful that I'll get some valuable help in here.  </p>
  
  <p>Best regards.  </p>
  
  <p>Paulo Ricardo Ferreira</p>