Hosting API on subpath e.g. /api when working with MVC.Core

I am trying to port a servicestack / mvc application to .Net Core. The ASP.Net Application uses ASP.NET MVC together with a ServiceStack based API.

The API is hosted under the path /api

When I try to accomplish the same in .NET Core (using the SimpleAuth.Mvc sample project) I cannot get this to work.

This is the code I tried:

public override void Configure(Funq.Container container)
  Plugins.Add(new SwaggerFeature());
  SetConfig(new HostConfig
    HandlerFactoryPath = "api",

This does not give me the desired result.

  • /api/metadata returns a 404 but /metadata still works
  • /api/swagger-ui/ returns a 404 but /swagger-ui/ works
  • The metadata description on /metdata is as expected
  • The services still are accessible from the root

This should now be resolved with the latest v1.0.26 on NuGet which you should be able to pull down with dotnet restore.

Although unlike in ASP.NET, in .NET Core you can host MVC + ServiceStack together within the same route namespace, i.e. without needing to host ServiceStack at a a /api custom path.

Thanks, works like a charm.
I really like my webpages and API separated, whilst running in the same web application.

1 Like