1
votes

there!

After some comings and goings, I finally got my very first MVC app working in my dev machine.

The scenario is as following:

  • it's an intranet app (therefore I'm using Windows Authentication)
  • it's a MVC 5 app (with Bootstrap and jQuery stuff - no .aspx pages)
  • Entity Framework 6 (Code First)
  • SQL Server Compact Edition
  • VS 2013 Express Edition
  • Server: Windows 2008 R2, running IIS 7
  • Hotfix KB980368 installed
  • IIS registered with asp.net (command aspnet_regiis.exe -i ran)

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:

  • Publish method: File System
  • Target location: the folder created on server
  • Configuration: Release
  • Databases: database publishing is not supported for this publish method

The target on server was filled with the following folders:

  • bin (System.Web.MVC, System.Web.Razor, etc )
  • Content
  • fonts
  • Scripts
  • Views

and the following files:

  • Global.asax
  • packages.config
  • web.config

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.

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.

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:

<a href="/Home/Contact">Contact</a>

Well, when I click this element I get a 404 - File or directory not found 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 navbars, links and so on.

Then I began to google 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 this one. I tried. Didn't work.

So, in IIS 7 the configuration is the following:

  • Application Pool: Framework: v4.0.30319, Managed Pipeline: Integrated, Identity: ApplicationPoolApplication
  • .NET Authorization Rules: Allow All Users
  • .NET Trust Levels: Full (internal)
  • Application Settings: ClientValidationEnabled: true, UnobtrusiveJavaScriptEnabled: true, webpages:Enabled: false, webpages:Version: 3.0.0.0
  • Connection Strings: DbControleDeAcesso: Data Source=|DataDirectory|\ControleDeAcesso.sdf; DbOrcamento: Data Source=|Data Directory|\Orcamento.sdf
  • Authentication: Anonymous Authentication: Disabled, ASP.NET Impersonation: Disabled, Forms Authentication: Disabled, Windows Authentication: Enabled
  • Handler Mappings
    • ExtensiolessUrlHandler-Integrated-4.0
      • Path: *.
      • State: Enabled
      • Path Type: Unspecified
      • Handler: System.Web.Handlers.TransferRequestHandler
      • Entry Type: Local
    • ExtensiolessUrlHandler-ISAP-4.0_32bit/64bit
      • Path: *.
      • State: Enabled
      • Path Type: Unspecified
      • Handler: IsapiModule
      • Entry Type: Inherited
  • Modules
    • UrlRoutingModule-4.0
      • Code: System.Web.RoutingModule
      • Module Type: Managed
      • Entry Type: Local

Bellow I present my web.config file:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <appSettings>
    <add key="webpages:Version" value="3.0.0.0" />
    <add key="webpages:Enabled" value="false" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
  </appSettings>
  <system.web>
    <compilation defaultLanguage="vb" targetFramework="4.5.1" />
    <httpRuntime targetFramework="4.5.1" />
  </system.web>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <dependentAssembly>
      <assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed" />
      <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
    </dependentAssembly>
    <dependentAssembly>
      <assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" />
      <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0" />
    </dependentAssembly>
    <dependentAssembly>
      <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
      <bindingRedirect oldVersion="1.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
    </dependentAssembly>
    <dependentAssembly>
      <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
      <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
    </dependentAssembly>
    <dependentAssembly>
      <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
      <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
    </dependentAssembly>
    <dependentAssembly>
      <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
      <bindingRedirect oldVersion="1.0.0.0-5.2.2.0" newVersion="5.2.2.0" />
    </dependentAssembly>
  </assemblyBinding>
  </runtime>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlCeConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="System.Data.SqlServerCe.4.0" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlServerCe.4.0" type="System.Data.Entity.SqlServerCompact.SqlCeProviderServices, EntityFramework.SqlServerCompact" />
    </providers>
  </entityFramework>
  <system.data>
     <DbProviderFactories>
       <remove invariant="System.Data.SqlServerCe.4.0" />
       <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" />
     </DbProviderFactories>
  </system.data>
  <connectionStrings>
      <remove name="LocalSqlServer" />
      <add name="DbControleDeAcesso" providerName="System.Data.SqlServerCe.4.0" connectionString="Data Source=|DataDirectory|\ControleDeAcesso.sdf" />
      <add name="DbOrcamento" providerName="System.Data.SqlServerCe.4.0" connectionString="Data Source=|DataDirectory|\Orcamento.sdf" />
  </connectionStrings>
  <system.webServer>
     <validation validateIntegratedModeConfiguration="false" />
     <security>
        <authentication>
            <anonymousAuthentication enabled="false" />
            <windowsAuthentication enabled="true" />
        </authentication>
    </security>
    <modules runAllManagedModulesForAllRequests="true">
        <remove name="UrlRoutingModule-4.0" />
        <add name="UrlRoutingModule-4.0" type="System.Web.Routing.UrlRoutingModule" preCondition="" />
    </modules>
    <handlers>
         <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
         <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
    </handlers>
    <defaultDocument>
        <files>
            <remove value="default.aspx" />
            <remove value="iisstart.htm" />
            <remove value="index.html" />
            <remove value="index.htm" />
            <remove value="Default.asp" />
            <remove value="Default.htm" />
        </files>
    </defaultDocument>
    <!-- <handlers>
        <add name="UrlRoutingHandler" preCondition="integratedMode" verb="*" path="UrlRouting.axd" type="System.Web.HttpForbiddenHandler, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
    </handlers> -->
  </system.webServer>
</configuration>  

I don't know whether it's relevant or not, but follows my RouteConfig class:

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 }
            );
        }
    }
}  

I believe I've showed all the significant informations regarding my issue. If I've omitted any, please, just let me know.

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.

I'm really hopeful that I'll get some valuable help in here.

Best regards.

Paulo Ricardo Ferreira

1
How come you add a virtual directory? Have you not added a Website in the sites folder?shammelburg
Hi, @SHammelburg! I created the folder at server. Published the website to that folder and then, in IIS, added a virtual directory targeting that folder. Thanks for your time.Paulo Ricardo Ferreira
so to which website did you add the virtual directory? When you are in IIS, you should add a website and link that to your folder on the server.shammelburg
Hi, @SHammelburg! That's exactly what I did. Thanks for your time.Paulo Ricardo Ferreira

1 Answers

0
votes

@paulo Ricardo Ferreira First Of all check the application pool is set to v4.0 if it's not than select it.and try to re register your 4.0 version using cmd.as i shown in figureenter image description here

Hit enter it will start installing than restart your system and than click on your route in iis which will be something like //administrator at the top and than go isapi and CGI Restrictions tab.Allow All the paths as i shown in image below. enter image description here