web-dev-qa-db-ja.com

IISで展開した後にのみAsp.net Web API例外: 'HelpPage_Default'という名前のルートがルートコレクションに既にあります

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>
31
Aminul

私はちょうど同じ問題に遭遇しました。以前に別のソリューションを自分のサイトにプッシュし、何らかの形で邪魔になっている残りのファイルがあったため、エラーが発生したと思います。

これを修正するために、Visual Studioを介してAzureサイトに発行するときに、「宛先の追加ファイルを削除する」というボックスをチェックしました。公開前にサーバー上にある古いファイルを手動で削除することもできると思います。この後、サイトはエラーなく正常に動作しました。

64
Tibincrunch
  1. Visual Studioでソリューションを右クリックし、[ソリューションのクリーニング]をクリックします。
  2. \ Project\bin \フォルダの下のすべてのファイルを削除します
  3. Visual Studio Cheersでソリューションを再構築します。
21
user5225916

名前空間をリファクタリングすることで名前空間の名前を変更しましたが、それを行うとこのハードコードされた文字列が見つかりませんでした:

プロジェクト>エリア> HelpPage> 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)",
4
Jeremy Thompson

プロジェクト名を変更した後も同じ問題が発生します。そう、

  1. ソリューション全体で正しい名前を見つけて置き換えます。
  2. クリーンなソリューション
  3. プロジェクトのbinおよびobjフォルダーを削除します。
  4. 再構築ソリューション

..はい、動作します。

1
King_Fisher

私はこの同じ問題を抱えており、同様の問題を持つ異なるスレッドから複数の提案されたソリューションを試してみましたが、どこにも行きませんでした。

最終的に、チームエクスプローラーからソリューションのクリーンコピーをチェックアウトしたところ、修正されました。

1
aemorales1