【问题标题】:Web Core API - cannot get the correct URL for the deployed serverWeb Core API - 无法获取已部署服务器的正确 URL
【发布时间】:2017-08-11 23:37:17
【问题描述】:

我能够从 C# 代码调用我部署的 Web API Core,但是从 AJAX 中我得到 404 错误。 我的jQuery代码如下;

var removeUser = function (e) {
    e.preventDefault();
    var $this = $(this);
    var $container = $this.closest(".container");
    $container.uniqueId();
    $.list.container = $container;
    $.list.id = $container.id;
    var $row = $this.closest(".row");
    $.list.row = $row;
    var userId = $this.data("sir-remove-id");
    var $sectionId = $this.closest("section")[0].id;
    var url;
    var callback = removeUserFromView;
    if ($sectionId === "SuperUserList") {
        url = GetHiddenField("sir-user-root-url") + userId + "/removeSuperUser";
    } else {
        var container = $("#" + $container[0].id);
        var item = container.find(".contractId");
        var contractId = item.val();
        url = GetHiddenField("sir-user-root-url") + contractId + "/" + userId + "/removeContractUser";
    }

    dataService.removeFromDatabase(callback, url);
}

在数据服务中;

removeFromDatabase = function (callback, url) {
            $.ajax({
                url: url,
                method: "DELETE"
            }).done(
                function (data) {
                    callback(data);
                });
        },

在开发中,我呼吁

http://localhost:xxx//api//users//18/removeSuperUser

作品

但是在我的测试服务器上我得到一个 404

http://testweb.xxx.com//api//users//27/removeSuperUser

在 web API Core 上,签名是

namespace Properties.API.Controllers
{
    [Route("api/users")]
    public class UserPermissionsController : BaseSirController
    {
       [HttpDelete("{userId}/removeSuperUser")]
        public async Task<IActionResult> RemoveSuperUser(int userId)
        {

那么为什么我会收到 404?

【问题讨论】:

    标签: jquery ajax asp.net-core-webapi


    【解决方案1】:

    我发现我错过的是部署的 URL 需要包含应用程序的名称。一旦我把它放进去,它就起作用了。

    【讨论】:

      猜你喜欢
      • 2021-03-22
      • 1970-01-01
      • 2018-05-10
      • 1970-01-01
      • 1970-01-01
      • 2023-03-06
      • 2012-11-01
      • 2017-10-12
      • 1970-01-01
      相关资源
      最近更新 更多