【问题标题】:Servicestack routes only resolving with // after hostname when route specifies /当路由指定 / 时,Servicestack 路由仅在主机名之后使用 / 解析
【发布时间】:2022-06-11 16:08:31
【问题描述】:

我有一个 net5.0 休息服务,ServiceStack 5.14 在 Visual Studio Professional 2022 中运行。

在 Apphost.cs 中像这样定义路由

public override RouteAttribute[] GetRouteAttributes(Type requestType)
    {
        var routes = base.GetRouteAttributes(requestType);
        routes.Each(x => x.Path = "/api" + x.Path);
        return routes;
    }

为我们提供一个 ServiceStack RouteAttribute.paths,如“/api/things”......一切都很好,正如预期的那样。

但如果我在 VS 中运行它并请求 http://localhost:64200/api/things 我会得到一个 Http 405 和一个“NotImplementedException”

如果我请求 http://localhost:64200//api/things(请注意端口后的“//”),它可以在 HTTP 200 上运行。遗憾的是,没有预料到会破坏我的客户端。

有人知道是什么原因造成的吗?我想可能是一些 Kestrel &/ Visual Studio 恶作剧,但我正在运行其他没有 ServiceStack 的 netcoreapps,它们按预期运行......

【问题讨论】:

    标签: asp.net-core servicestack


    【解决方案1】:

    由于您为 API 动态使用 /api 路由,因此您需要禁用 built in /api route

    ConfigurePlugin<PredefinedRoutesFeature>(feature => feature.JsonApiRoute = null);
    

    【讨论】:

      猜你喜欢
      • 2013-11-10
      • 1970-01-01
      • 1970-01-01
      • 2019-06-14
      • 1970-01-01
      • 2019-03-15
      • 1970-01-01
      • 2020-04-04
      • 1970-01-01
      相关资源
      最近更新 更多