web api控制器中的问题 [英] Problem in web api controllers

查看:85
本文介绍了web api控制器中的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HI,

我正在使用VB语言的Visual Studio 2017工作web api项目

我已经创建了一些控制器,他们在我的工作正常电脑和在线,

然后我使用与旧电脑相同的代码创建了新的控制器,它们在我的电脑上正常工作但是当我从在线托管中呼叫它时,我得到了404响应没有找到与控制器相匹配的类型



我尝试了什么:



一个工作控制器的例子:


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





一个回复404的控制器的例子



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

推荐答案

我猜你没有将你的\Controllers目录移动到你的部署网站现场。或者,文件夹不在正确的路径中。这只是一个猜测,但它可能会让你找到答案。祝你好运。
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.


这篇关于web api控制器中的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆