仅在IIS部署之后的Asp.net web api例外:名为' HelpPage_Default'已经在路线集合中

时间:2014-12-29 06:26:24

标签: asp.net-mvc iis asp.net-web-api

我已经阅读了this问题,并尝试了那里提到的解决方案但我只是在将应用程序发布到远程服务器的IIS之后才得到此异常。在我本地计算机的IIS中,应用程序运行正常。我不知道在该服务器上导致此异常的原因是什么:

Server Error in '/' Application.

A route named 'HelpPage_Default' is already in the route collection. Route names must be unique.
Parameter name: name

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.ArgumentException: A route named 'HelpPage_Default' is already in the route collection. Route names must be unique.
Parameter name: name
Source Error:  
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace: 

[ArgumentException: A route named 'HelpPage_Default' is already in the route collection. Route names must be unique.
Parameter name: name]
   System.Web.Routing.RouteCollection.Add(String name, RouteBase item) +3713577
   System.Web.Mvc.RouteCollectionExtensions.MapRoute(RouteCollection routes, String name, String url, Object defaults, Object constraints, String[] namespaces) +350
   System.Web.Mvc.AreaRegistrationContext.MapRoute(String name, String url, Object defaults, Object constraints, String[] namespaces) +95
   XbimServer.Areas.HelpPage.HelpPageAreaRegistration.RegisterArea(AreaRegistrationContext context) +174
   System.Web.Mvc.AreaRegistration.RegisterAllAreas(RouteCollection routes, IBuildManager buildManager, Object state) +323
   BimServer.WebApiApplication.Application_Start() +23

[HttpException (0x80004005): A route named 'HelpPage_Default' is already in the route collection. Route names must be unique.
Parameter name: name]
   System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +12600317
   System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +175
   System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +304
   System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +404
   System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +475

[HttpException (0x80004005): A route named 'HelpPage_Default' is already in the route collection. Route names must be unique.
Parameter name: name]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +12617364
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +159
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +12456981

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.34212

这是我在Global.asax.cs设置的内容:

protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
        }

我的RouteConfig.cs

public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
            );
        }

我的WebApiConfig.cs

config.MapHttpAttributeRoutes();

    config.Routes.MapHttpRoute(
        name: "DefaultApi",
        routeTemplate: "api/{controller}/{id}",
        defaults: new { id = RouteParameter.Optional }
    );

我还对我的web.config文件进行了以下更改:

<system.webServer>
    <modules>
      <remove name="WebDAVModule" />
    </modules>
    <handlers>
      <remove name="WebDAV" />
      <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
      <remove name="OPTIONSVerbHandler" />
      <remove name="TRACEVerbHandler" />
      <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
    </handlers>
  </system.webServer>

5 个答案:

答案 0 :(得分:62)

我刚遇到同样的问题。我认为错误是因为我之前已经将另一个解决方案推送到我的网站,并且有一些剩余的文件在某种程度上妨碍了我们。

为了解决这个问题,我选中了“#34;删除目的地的其他文件&#34;通过Visual Studio发布到我的Azure站点。我想你可以在发布之前手动删除服务器上的任何旧文件。在此之后,网站运行良好,没有任何错误。

答案 1 :(得分:20)

  1. 在Visual Studio中右键单击您的解决方案 - &gt;单击“清洁解决方案”
  2. 删除\ Project \ bin \ folders
  3. 下的所有文件
  4. 在Visual Studio中重建您的解决方案 欢呼声。

答案 2 :(得分:4)

我通过重构命名空间并重命名这个命名空间并错过了这个硬编码字符串:

项目&gt;区域&gt; HelpPage&gt; AppStart的:

public static class HelpPageConfig
    {
        [SuppressMessage("Microsoft.Globalization", "CA1303:Do not pass literals as localized parameters",
            MessageId = "<CORRECT NAMESPACE>.Areas.HelpPage.TextSample.#ctor(System.String)",

答案 3 :(得分:1)

我遇到了同样的问题,尝试了来自不同线程的多个提出的解决方案,这些解决方案存在类似的问题而无处可寻。

我终于从团队资源管理器中检查了一份干净的解决方案,并为我修复了这个问题。

答案 4 :(得分:0)

在本地IIS上部署应用程序时,我遇到了同样的问题。我的发布目录和IIS托管目录相同。 我尝试了以下步骤,对我有用:

  1. 点击解决方案>>发布
  2. 删除现有文件>>设置>>展开文件发布选项
  3. 选中复选框,在发布之前删除所有现有文件为true;
  4. 选中发布期间的预编译复选框为true。