Where does Web API look in a Web Forms project for Controllers?

Pleabledamrah

New Member
I am using Web API in my Web Forms project. I have the following code in my project's \[code\]Application_Start\[/code\] method in Global.asax:\[code\]GlobalConfiguration.Configuration.Routes.MapHttpRoute("ApiDefault", "api/{controller}/{id}", New With {.id = RouteParameter.Optional})\[/code\]This is basically copied and pasted from a Microsoft tutorial on the subject.I also have a test controller named \[code\]ValuesController\[/code\]. This class is just the default Web API controller one gets when creating a controller from the Add New Item wizard and is in a folder in my Web Forms site named \[code\]Controllers\[/code\]:\[code\]Imports System.NetImports System.Web.HttpPublic 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 SubEnd Class\[/code\]HOWEVER - when I go to \[code\]http://localhost/api/Values\[/code\] - instead of seeing some XML serializing the strings \[code\]value1\[/code\] and \[code\]value2\[/code\], I see an error message like so:\[code\]<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>\[/code\]So - clearly, routing is working, since instead of getting a 404 I get a message saying that the route itself doesn't resolve to anything. But the route should resolve to something - specifically, my \[code\]ValuesController\[/code\] class which is even in a folder named \[code\]Controllers\[/code\]. Anyone know what I'm doing wrong?Thanks in advance.
 
Back
Top