Asp.net Web API异常(仅在IIS上部署后出现):路由集合中已存在名为ウHelpPage_Default Ж的路由,

c9qzyr3d  于 2022-11-12  发布在  .NET
关注(0)|答案(7)|浏览(430)

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

  1. Server Error in '/' Application.
  2. A route named 'HelpPage_Default' is already in the route collection. Route names must be unique.
  3. Parameter name: name
  4. 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.
  5. Exception Details: System.ArgumentException: A route named 'HelpPage_Default' is already in the route collection. Route names must be unique.
  6. Parameter name: name
  7. Source Error:
  8. 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.
  9. Stack Trace:
  10. [ArgumentException: A route named 'HelpPage_Default' is already in the route collection. Route names must be unique.
  11. Parameter name: name]
  12. System.Web.Routing.RouteCollection.Add(String name, RouteBase item) +3713577
  13. System.Web.Mvc.RouteCollectionExtensions.MapRoute(RouteCollection routes, String name, String url, Object defaults, Object constraints, String[] namespaces) +350
  14. System.Web.Mvc.AreaRegistrationContext.MapRoute(String name, String url, Object defaults, Object constraints, String[] namespaces) +95
  15. XbimServer.Areas.HelpPage.HelpPageAreaRegistration.RegisterArea(AreaRegistrationContext context) +174
  16. System.Web.Mvc.AreaRegistration.RegisterAllAreas(RouteCollection routes, IBuildManager buildManager, Object state) +323
  17. BimServer.WebApiApplication.Application_Start() +23
  18. [HttpException (0x80004005): A route named 'HelpPage_Default' is already in the route collection. Route names must be unique.
  19. Parameter name: name]
  20. System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +12600317
  21. System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +175
  22. System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +304
  23. System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +404
  24. System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +475
  25. [HttpException (0x80004005): A route named 'HelpPage_Default' is already in the route collection. Route names must be unique.
  26. Parameter name: name]
  27. System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +12617364
  28. System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +159
  29. System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +12456981
  30. Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.34212

下面是我在Global.asax.cs上设置的内容:

  1. protected void Application_Start()
  2. {
  3. AreaRegistration.RegisterAllAreas();
  4. GlobalConfiguration.Configure(WebApiConfig.Register);
  5. FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
  6. RouteConfig.RegisterRoutes(RouteTable.Routes);
  7. BundleConfig.RegisterBundles(BundleTable.Bundles);
  8. }

我的RouteConfig.cs

  1. public static void RegisterRoutes(RouteCollection routes)
  2. {
  3. routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
  4. routes.MapRoute(
  5. name: "Default",
  6. url: "{controller}/{action}/{id}",
  7. defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
  8. );
  9. }

还有我的WebApiConfig.cs

  1. config.MapHttpAttributeRoutes();
  2. config.Routes.MapHttpRoute(
  3. name: "DefaultApi",
  4. routeTemplate: "api/{controller}/{id}",
  5. defaults: new { id = RouteParameter.Optional }
  6. );

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

  1. <system.webServer>
  2. <modules>
  3. <remove name="WebDAVModule" />
  4. </modules>
  5. <handlers>
  6. <remove name="WebDAV" />
  7. <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
  8. <remove name="OPTIONSVerbHandler" />
  9. <remove name="TRACEVerbHandler" />
  10. <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
  11. </handlers>
  12. </system.webServer>
i86rm4rw

i86rm4rw1#

我刚刚遇到了同样的问题。我认为错误是因为我以前向我的网站推送了另一个解决方案,而有剩余的文件不知何故碍事。
为了解决这个问题,我在通过Visual Studio发布到我的Azure站点时选中了“在目标位置删除其他文件”的复选框。我认为您可以在发布之前手动删除服务器上的任何旧文件。在此之后,站点运行良好,没有任何错误。

vltsax25

vltsax252#

1.在Visual Studio中右键单击解决方案-〉单击“清理解决方案
1.删除\Project\bin\文件夹下的所有文件
1.在Visual Studio Cheers中重新生成解决方案。

dgtucam1

dgtucam13#

我通过重构命名空间来重命名命名它,但这样做却遗漏了以下硬编码字符串:
项目〉区域〉帮助页面〉应用程序启动:

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

eqzww0vc4#

我在重命名项目名称后也遇到了同样的问题。所以,
1.在整个解决方案中查找并替换正确的名称。
1.清洁溶液
1.删除bin & obj项目的文件夹。
1.重新生成解决方案
..是的,它工作。

b1uwtaje

b1uwtaje5#

我有这个相同的问题,并尝试了多个提出的解决方案,从不同的线程与类似的问题,并没有得到任何结果。
我终于从Team Explorer中 checkout 了一个干净的解决方案副本,这为我修复了它。

brqmpdu1

brqmpdu16#

我遇到了这个问题,原因是我有一个 * 那个*Web项目引用了另一个Web项目。我只是删除了引用,不需要清理解决方案。

8nuwlpux

8nuwlpux7#

我在本地IIS上部署应用程序时遇到了同样的问题。我的发布目录和IIS托管目录相同。我尝试了以下步骤,它对我很有效:
1.点击解决方案〉〉发布
1.删除现有文件〉〉设置〉〉扩展文件发布选项
1.选中复选框“发布前删除所有现有文件”为真;
1.核取核取方块“出版时先行编译”为true。

相关问题