Home > front end >  Servicestack routes only resolving with // after hostname when route specifies /
Servicestack routes only resolving with // after hostname when route specifies /

Time:06-14

I have a net5.0 rest service with ServiceStack 5.14 running in Visual Studio Professional 2022.

Routes are getting defined like this in a Apphost.cs

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

Giving us a ServiceStack RouteAttribute.paths like "/api/things" .. all good, as expected.

But if I run it in VS and request http://localhost:64200/api/things I get an Http 405 and a "NotImplementedException"

And if I request http://localhost:64200//api/things (Note the '//' after the port) it works HTTP 200. Sadly not expected and breaks my client.

Anybody got any ideas what's causing this? I thought maybe some Kestrel &/ Visual Studio shenanigans but I am running other netcoreapps without ServiceStack and they serve as expected...

CodePudding user response:

Since you’re dynamically making use of the /api route for your APIs, you need to disable the built in /api route:

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