Click here to Skip to main content
15,886,422 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
HI,
I'm working in web api project using Visual studio 2017 in VB language
I've created some controllers and they're working fine on my pc and online,
then I've created new controllers using the same code as the old ones and they are working fine on my pc but when I call them from the hosting online I get the 404 response "No type was found that matches the controller named"

What I have tried:

an example of a working controller:
Imports System.Web.Http

Namespace Controllers
    Public Class BanksController
        Inherits ApiController

        Dim Table As String = "Banks"
        ' GET: api/Banks
        Public Function GetValues() As Object
            Return SqlToJson("SELECT BankId, BankName FROM " & Table)

        End Function

        ' GET: api/Banks/5
        Public Function GetValue(ByVal id As Integer) As Object
            Return SqlToJson("SELECT BankId, BankName FROM " & Table & " Where BankId = " & id)
        End Function

        ' POST: api/Banks
        Public Function PostValue(<FromBody()> ByVal value As Object) As Object
            Return InsertFromJson(value, Table)
        End Function

        ' PUT: api/Banks/5
        Public Function PutValue(ByVal id As Integer, <FromBody()> ByVal value As Object) As Object
            Return UpdateFromJson(value, Table, " Where BankId = " & id)
        End Function

        ' DELETE: api/Banks/5
        Public Function DeleteValue(ByVal id As Integer) As Object
            Return DeleteRecord(Table, " Where BankId = " & id)
        End Function

    End Class

End Namespace


an example of a controller who responses with 404
Imports System.Web.Http

<pre lang="vb">Namespace Controllers
    Public Class BuildingsController
        Inherits ApiController

        Dim Table As String = "Buildings"
        ' GET: api/Buildings
        Public Function GetValues() As Object
            Return SqlToJson("SELECT * FROM " & Table)

        End Function

        ' GET: api/Buildings/5
        Public Function GetValue(ByVal id As Integer) As Object
            Return SqlToJson("SELECT * FROM " & Table & " Where BuildingId = " & id)
        End Function

        ' POST: api/Buildings
        Public Function PostValue(<FromBody()> ByVal value As Object) As Object
            Return InsertFromJson(value, Table)
        End Function

        ' PUT: api/Buildings/5
        Public Function PutValue(ByVal id As Integer, <FromBody()> ByVal value As Object) As Object
            Return UpdateFromJson(value, Table, " Where BuildingId = " & id)
        End Function

        ' DELETE: api/Buildings/5
        Public Function DeleteValue(ByVal id As Integer) As Object
            Return DeleteRecord(Table, " Where BuildingId = " & id)
        End Function

    End Class
End Namespace
Posted
Updated 3-Apr-19 2:23am
Comments
Mohamed Sultan 3-Apr-19 5:58am    
Imports System.Net.Http.Headers
Imports System.Web.Http
Imports System.Web.Http.Cors

Public Module WebApiConfig
Public Sub Register(ByVal config As HttpConfiguration)
' Web API configuration and services
config.EnableCors(New EnableCorsAttribute("*", "*", "*"))
' Web API routes
config.MapHttpAttributeRoutes()

config.Routes.MapHttpRoute(name:="ControllersApi", routeTemplate:="api/{controller}/{id}", defaults:=New With {.id = RouteParameter.Optional})

'config.Routes.MapHttpRoute(
' name: "ControllersApi",
' routeTemplate: "api/{controller}/{action}/{id}",
' defaults: New { id = RouteParameter.Optional }
');

config.Formatters.JsonFormatter.SupportedMediaTypes.Add(New MediaTypeHeaderValue("text/html"))

End Sub
End Module

1 solution

I'm guessing that you didn't move your \Controllers directory to your deployment web site. Or, the folder just isn't in the correct path. This is just a guess but it may get you toward the answer. Good luck.
 
Share this answer
 
Comments
Mohamed Sultan 7-Apr-19 8:24am    
it was something close to that, when I publish directly from Visual Studio not all files are uploaded, so I published on a local folder on my hard disk then uploaded the publish by FileZilla and it worked fine!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900