【问题标题】:No routes working, Web API, when published to server发布到服务器时,没有路由工作,Web API
【发布时间】:2016-01-23 10:56:26
【问题描述】:

当我尝试将我的 Web API 发布到服务器时,我收到以下消息

“未找到与请求 URI 匹配的 HTTP 资源” "没有找到与名为 'test' 的控制器匹配的类型。"

一切都在我的机器上本地运行。只是试图让测试控制器工作,然后努力修复其他控制器,因此我的 Web API 中有其他注册路由。

http://localhost:4159/api/test/1

http://intranetserver/project/api/test/1

这是控制器

Public Class TestController
Inherits ApiController

Public Function GetValue(ByVal id As Integer) As String
    Return "value"
End Function 

这是 WebApiConfig.vb

Public Class WebApiConfig Public Shared Sub Register(ByVal config As HttpConfiguration) config.Routes.MapHttpRoute( _ name:="DefaultApi", _ routeTemplate:="api/{controller}/{id}", _ defaults:=New With {.id = RouteParameter.Optional} _ ) ' config.Routes.MapHttpRoute( _ ' name:="GetVehiclesByDateRange", _ ' routeTemplate:="api/{controller}/{startDate}/{endDate}" _ ') config.Routes.MapHttpRoute( _ name:="GetImportersByDateTimeRange", _ routeTemplate:="api/{controller}/{startDateTime}/{endDateTime}" _ ) config.Routes.MapHttpRoute( _ name:="GetPagedData", _ routeTemplate:="api/{controller}/{pageNumber}/{pageSize}" _ ) End Sub End Class

这是在 Global.asax.vb 文件中找到的内容


  Sub Application_Start()

        AreaRegistration.RegisterAllAreas()

        WebApiConfig.Register(GlobalConfiguration.Configuration)
        FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters)
        RouteConfig.RegisterRoutes(RouteTable.Routes)
        BundleConfig.RegisterBundles(BundleTable.Bundles)

        CorsConfig.RegisterCors(GlobalConfiguration.Configuration)

        ''NOTE: Remove the Basic Authentication mechanism below to open the service to all calls. And also comment out any  attributes on Controllers.
        GlobalConfiguration.Configuration.MessageHandlers.Add(New BasicAuthMessageHandler() With {.PrincipalProvider = New DummyPrincipalProvider()})

    End Sub


有什么想法吗?

【问题讨论】:

  • 您可以发布您正在访问的网址吗?
  • 上面加了伪url,是内网服务
  • 试试 routeTemplate:="project/api/{controller}/{id}"
  • @ArghyaC 不起作用

标签: .net vb.net asp.net-web-api asp.net-web-api-routing


【解决方案1】:

问题解决了,万岁!

对我自己来说,这与在服务器上找到的引用不匹配有关。

“API 使用程序集解析器扫描程序集并找出控制器类型”
这就是为什么我不断得到
“未找到与名为‘test’的控制器匹配的类型。”

引用自以下帖子

Getting the "no type was found that matches the controller named" error message during Ajax Request

我有一个不同版本的 oracle 被引用然后在服务器上找到什么。

因此,您从 Web API 收到的消息可能具有误导性。

确保您的 .dll 引用在生产环境中与在本地计算机上的引用相同。

希望这可以节省您的时间。

【讨论】:

    猜你喜欢
    • 2013-03-18
    • 1970-01-01
    • 2018-06-30
    • 2011-01-29
    • 2019-07-22
    • 2015-07-28
    • 1970-01-01
    • 2020-07-09
    • 1970-01-01
    相关资源
    最近更新 更多