Asp.net Web API在控制器的Web窗体项目中的位置?
我在Web窗体项目中使用Web API。我在Global.asax中的项目Asp.net Web API在控制器的Web窗体项目中的位置?,asp.net,asp.net-mvc-4,asp.net-web-api,Asp.net,Asp.net Mvc 4,Asp.net Web Api,我在Web窗体项目中使用Web API。我在Global.asax中的项目应用程序\u Start方法中有以下代码: GlobalConfiguration.Configuration.Routes.MapHttpRoute("ApiDefault", "api/{controller}/{id}", New With {.id = RouteParameter.Optional}) 这基本上是从有关该主题的Microsoft教程中复制和粘贴的 我还有一个名为valuescoontroller
应用程序\u Start
方法中有以下代码:
GlobalConfiguration.Configuration.Routes.MapHttpRoute("ApiDefault", "api/{controller}/{id}", New With {.id = RouteParameter.Optional})
这基本上是从有关该主题的Microsoft教程中复制和粘贴的
我还有一个名为valuescoontroller
的测试控制器。此类只是从“添加新项目向导”创建控制器时获得的默认Web API控制器,位于我的Web窗体网站中名为Controllers
的文件夹中:
Imports System.Net
Imports System.Web.Http
Public Class ValuesController
Inherits ApiController
' GET api/<controller>
Public Function GetValues() As IEnumerable(Of String)
Return New String() {"value1", "value2"}
End Function
' GET api/<controller>/5
Public Function GetValue(ByVal id As Integer) As String
Return "value"
End Function
' POST api/<controller>
Public Sub PostValue(<FromBody()> ByVal value As String)
End Sub
' PUT api/<controller>/5
Public Sub PutValue(ByVal id As Integer, <FromBody()> ByVal value As String)
End Sub
' DELETE api/<controller>/5
Public Sub DeleteValue(ByVal id As Integer)
End Sub
End Class
很明显,路由正在工作,因为我没有得到404,而是得到一条消息,说路由本身没有解决任何问题。但是路由应该解析到某个对象,具体地说,就是我的valuescoontroller
类,它甚至位于名为Controllers
的文件夹中
有人知道我做错了什么吗
提前谢谢。我想好了。这是因为MVC显然要求Controllers文件夹与声明路由的文件处于同一级别,而不是(正如我以前所认为的)根级别
呃。其他路线有效吗?是的,其他路线似乎有效。
<Error>
<Message>No HTTP resource was found that matches the request URI 'http://localhost/api/Values'.</Message>
<MessageDetail>No type was found that matches the controller named 'Values'.</MessageDetail>
</Error>