为什么我的服务器上的路由工作方式不同

时间:2016-04-22 16:08:00

标签: asp.net-mvc

附件是一个屏幕抓取,显示ASP MVC如何将/ Tafsirs路由到正确的控制器,并在运行Release版本时在我的LocalHost上呈现视图:

Working on LocalHost

但是当我将其发布到Live server时,我收到以下错误

enter image description here

这是我的web.config

<?xml version="1.0" encoding="utf-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=152368
  -->
<configuration><?xml version="1.0" encoding="utf-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=152368
  -->
<configuration>
  <configSections>

    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <connectionStrings>
    <add name="DefaultConnection" providerName="System.Data.SqlClient" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-QuranX-20130628131431;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-QuranX-20130628131431.mdf" />
  </connectionStrings>
  <appSettings>
    <add key="webpages:Version" value="2.0.0.0" />
    <add key="webpages:Enabled" value="false" />
    <add key="PreserveLoginUrl" value="true" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
  </appSettings>
  <!--
    For a description of web.config changes for .NET 4.5 see http://go.microsoft.com/fwlink/?LinkId=235367.

    The following attributes can be set on the <httpRuntime> tag.
      <system.Web>
        <httpRuntime targetFramework="4.5" />
      </system.Web>
  -->
  <system.web>
    <!--compilation debug="true" targetFramework="4.5" /-->
    <customErrors mode="RemoteOnly" />
    <httpRuntime relaxedUrlToFileSystemMapping="true" />
    <compilation debug="true" targetFramework="4.5" />
    <authentication mode="Forms">
      <forms loginUrl="~/Account/Login" timeout="2880" />
    </authentication>
    <pages controlRenderingCompatibilityVersion="4.0">
      <namespaces>
        <add namespace="System.Web.Helpers" />
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Optimization" />
        <add namespace="System.Web.Routing" />
        <add namespace="System.Web.WebPages" />
      </namespaces>
    </pages>





  </system.web>
  <system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
    <modules runAllManagedModulesForAllRequests="true" />

  </system.webServer>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089" />
        <bindingRedirect oldVersion="1.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-1.3.0.0" newVersion="1.3.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
  </entityFramework>
</configuration>

以下是我的观点中的Web.config

<?xml version="1.0"?>

<configuration>
  <configSections>
    <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
      <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
      <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
    </sectionGroup>
  </configSections>

  <system.web.webPages.razor>
    <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <pages pageBaseType="System.Web.Mvc.WebViewPage">
      <namespaces>
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Optimization"/>
        <add namespace="System.Web.Routing" />
      </namespaces>
    </pages>
  </system.web.webPages.razor>

  <appSettings>
    <add key="webpages:Enabled" value="false" />
  </appSettings>

  <system.web>
    <httpHandlers>
      <add path="*" verb="*" type="System.Web.HttpNotFoundHandler"/>
    </httpHandlers>

    <!--
        Enabling request validation in view pages would cause validation to occur
        after the input has already been processed by the controller. By default
        MVC performs request validation before a controller processes the input.
        To change this behavior apply the ValidateInputAttribute to a
        controller or action.
    -->
    <pages
        validateRequest="false"
        pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
        pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
        userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
      <controls>
        <add assembly="System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc" />
      </controls>
    </pages>
  </system.web>

  <system.webServer>
    <validation validateIntegratedModeConfiguration="false" />

    <handlers>
      <remove name="BlockViewHandler"/>
      <add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
    </handlers>
  </system.webServer>
</configuration>

这是我的路线 -

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

namespace QuranX
{
    public class RouteConfig
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
            RegisterSiteMapRoutes(routes);
            RegisterHadithsByVerseRoutes(routes);
            RegisterTafsirsByVerseRoutes(routes);
            RegisterQuranRoutes(routes);
            RegisterAnalysisRoutes(routes);
            RegisterTafsirRoutes(routes);
            RegisterHadithRoutes(routes);
            RegisterSearchRoutes(routes);
            RegisterMiscRoutes(routes);
            //
            RegisterMovedRoutes(routes);
        }

        static void RegisterMiscRoutes(RouteCollection routes)
        {
            routes.MapRoute(
                name: "Help",
                url: "Help",
                defaults: new
                {
                    Controller = "Help",
                    Action = "Index"
                }
            );
            routes.MapRoute(
                name: "About",
                url: "About",
                defaults: new
                {
                    Controller = "Home",
                    Action = "About"
                }
            );
        }

        static void RegisterSearchRoutes(RouteCollection routes)
        {
            routes.MapRoute(
                name: "Search",
                url: "Search",
                defaults: new
                {
                    Controller = "Search",
                    Action = "Index"
                }
            );

            routes.MapRoute(
                name: "",
                url: "Search/Help",
                defaults: new
                {
                    Controller = "Search",
                    Action = "Help"
                }
            );

        }

        static void RegisterMovedRoutes(RouteCollection routes)
        {
            routes.MapRoute(
                name: "",
                url: "Analysis/{Chapter}/{Verse}",
                defaults: new
                {
                    Controller = "Redirect",
                    Action = "Redirect",
                    NewController = "Analysis",
                    NewAction = "Verse"
                },
                constraints: new
                {
                    Chapter = @"\d+",
                    Verse = @"\d+"
                }
            );

            routes.MapRoute(
                name: "",
                url: "Tafsirs/{Chapter}/{Verse}",
                defaults: new
                {
                    Controller = "Redirect",
                    Action = "Redirect",
                    NewController = "TafsirsByVerse",
                    NewAction = "Verse"
                },
                constraints: new
                {
                    Chapter = @"\d+",
                    Verse = @"\d+"
                }
            );

            routes.MapRoute(
                name: "",
                url: "Hadiths/{Chapter}/{Verse}",
                defaults: new
                {
                    Controller = "Redirect",
                    Action = "Redirect",
                    NewController = "HadithsByVerse",
                    NewAction = "Verse"
                },
                constraints: new
                {
                    Chapter = @"\d+",
                    Verse = @"\d+"
                }
            );


        }

        static void RegisterSiteMapRoutes(RouteCollection routes)
        {
            routes.MapRoute(
                name: "",
                url: "SiteMaps/Quran.xml",
                defaults: new
                {
                    Controller = "SiteMap",
                    Action = "Quran"
                }
            );

            routes.MapRoute(
                name: "",
                url: "SiteMaps/tafsir/{tafsirCode}-{PageIndex}.xml",
                defaults: new
                {
                    Controller = "SiteMap",
                    Action = "Tafsir"
                }
            );

            routes.MapRoute(
                name: "",
                url: "SiteMaps/hadith/{collectionCode}-{PageIndex}.xml",
                defaults: new
                {
                    Controller = "SiteMap",
                    Action = "Hadith"
                }
            );
        }

        static void RegisterHadithRoutes(RouteCollection routes)
        {
            routes.MapRoute(
                name: "Hadiths",
                url: "Hadiths",
                defaults: new
                {
                    Controller = "Hadith",
                    Action = "Index"
                }
            );

            routes.MapRoute(
                name: "",
                url: "Hadith/RedirectToChapterVerse",
                defaults: new
                {
                    Controller = "Hadith",
                    Action = "RedirectToChapterVerse"
                }
            );

            routes.MapRoute(
                name: "",
                url: "Hadith/{CollectionCode}/{*Path}",
                defaults: new
                {
                    Controller = "Hadith",
                    Action = "Collection",
                    Path = UrlParameter.Optional
                }
            );

        }

        static void RegisterTafsirRoutes(RouteCollection routes)
        {
            routes.MapRoute(
                name: "Tafsirs",
                url: "Tafsirs",
                defaults: new
                {
                    Controller = "Tafsir",
                    Action = "Index"
                }
            );

            routes.MapRoute(
                name: "",
                url: "Tafsir/{Tafsir}",
                defaults: new
                {
                    Controller = "Tafsir",
                    Action = "CommentaryIndexes"
                }
            );


            routes.MapRoute(
                name: "",
                url: "Tafsir/{Tafsir}/{Chapter}.{Verse}",
                defaults: new
                {
                    Controller = "Tafsir",
                    Action = "Verse"
                },
                constraints: new
                {
                    Chapter = @"\d+",
                    Verse = @"\d+"
                }
            );

            routes.MapRoute(
                    name: "",
                    url: "Tafsir/{Tafsir}/RedirectToChapterVerse",
                    defaults: new
                    {
                        Controller = "Tafsir",
                        Action = "RedirectToChapterVerse"
                    }
                );
        }

        static void RegisterTafsirsByVerseRoutes(RouteCollection routes)
        {
            routes.MapRoute(
                    name: "",
                    url: "Tafsirs/{Chapter}.{Verse}",
                    defaults: new
                    {
                        Controller = "TafsirsByVerse",
                        Action = "Verse"
                    },
                    constraints: new
                    {
                        Chapter = @"\d+",
                        Verse = @"\d+"
                    }
                );

            routes.MapRoute(
                    name: "",
                    url: "Tafsirs/RedirectToChapterVerse",
                    defaults: new
                    {
                        Controller = "TafsirsByVerse",
                        Action = "RedirectToChapterVerse"
                    }
                );
        }

        static void RegisterHadithsByVerseRoutes(RouteCollection routes)
        {
            routes.MapRoute(
                    name: "",
                    url: "Hadiths/{Chapter}.{Verse}",
                    defaults: new
                    {
                        Controller = "HadithsByVerse",
                        Action = "Verse"
                    },
                    constraints: new
                    {
                        Chapter = @"\d+",
                        Verse = @"\d+"
                    }
                );

            routes.MapRoute(
                    name: "",
                    url: "Hadiths/RedirectToChapterVerse",
                    defaults: new
                    {
                        Controller = "HadithsByVerse",
                        Action = "RedirectToChapterVerse"
                    }
                );
        }

        static void RegisterQuranRoutes(RouteCollection routes)
        {
            routes.MapRoute(
                    name: "Quran",
                    url: "",
                    defaults: new
                    {
                        Controller = "Quran",
                        Action = "Chapters",
                    }
                );

            routes.MapRoute(
                    name: "",
                    url: "{Chapter}.{Verse}-{LastVerse}",
                    defaults: new
                    {
                        Controller = "Quran",
                        Action = "Verse"
                    },
                    constraints: new
                    {
                        Chapter = @"\d+",
                        Verse = @"\d+",
                        LastVerse = @"\d+"
                    }
                );

            routes.MapRoute(
                    name: "",
                    url: "{Chapter}.{Verse}",
                    defaults: new
                    {
                        Controller = "Quran",
                        Action = "Verse",
                        LastVerse = -1
                    },
                    constraints: new
                    {
                        Chapter = @"\d+",
                        Verse = @"\d+"
                    }
                );

            routes.MapRoute(
                    name: "",
                    url: "{Chapter}",
                    defaults: new
                    {
                        Controller = "Quran",
                        Action = "Verse",
                        Verse = 1,
                        LastVerse = -1
                    },
                    constraints: new
                    {
                        Chapter = @"\d+"
                    }
                );

            routes.MapRoute(
                    name: "",
                    url: "Quran/RedirectToChapter",
                    defaults: new
                    {
                        Controller = "Quran",
                        Action = "RedirectToChapter"
                    }
                );

            routes.MapRoute(
                    name: "",
                    url: "Quran/RedirectToChapterVerse",
                    defaults: new
                    {
                        Controller = "Quran",
                        Action = "RedirectToChapterVerse"
                    }
                );

            routes.MapRoute(
                    name: "",
                    url: "Quran/GetVersesView",
                    defaults: new
                    {
                        Controller = "Quran",
                        Action = "GetVersesView"
                    }
                );

            routes.MapRoute(
                name: "",
                url: "{*Verses}",
                defaults: new
                {
                    Controller = "Quran",
                    Action = "MultipleVerses"
                },
                constraints: new
                {
                    Verses = @"^(\d+\.\d+(-\d+)?)(,(\d+\.\d+(-\d+)?))*$"
                }
            );
        }

        static void RegisterAnalysisRoutes(RouteCollection routes)
        {
            routes.MapRoute(
                    name: "",
                    url: "Analysis/{Chapter}.{Verse}",
                    defaults: new
                    {
                        Controller = "Analysis",
                        Action = "Verse"
                    },
                    constraints: new
                    {
                        Chapter = @"\d+",
                        Verse = @"\d+"
                    }
                );

            routes.MapRoute(
                    name: "",
                    url: "Analysis/RedirectToChapterVerse",
                    defaults: new
                    {
                        Controller = "Analysis",
                        Action = "RedirectToChapterVerse"
                    }
                );

            routes.MapRoute(
                    name: "",
                    url: "Analysis/Root/{Root}",
                    defaults: new
                    {
                        Controller = "Analysis",
                        Action = "Root"
                    }
                );

        }

    }
}

事实上,整个项目都在github上提供 - 这一直有效,直到我最近重新上传项目。应用程序的路由区域没有任何变化,所以我只能认为这是ISP安装的IIS不同,尽管他们坚持没有任何改变。

1 个答案:

答案 0 :(得分:0)

这似乎是一个部署问题。某种方式,/ Views文件夹的内容被上传到站点的根文件夹,导致名为Tafsirs的文件夹,因此IIS不允许该URL,因为它会导致列出静态文件。