MVC RequestDto.ToAbsoluteUri Does Not Include HostConfig.HandlerFactoryPath

When using ServiceStack 5.5 with MVC, the RequestDto.ToAbsoluteUri() returns a URL without the HostConfig.HandlerFactoryPath. What am I doing wrong?

AppHost : AppHostBase


        SetConfig(new HostConfig
            HandlerFactoryPath = "api"

The reverse routing extension methods are client libraries that only includes the route from the Base URL, it doesn’t include the BaseURL which the HandlerFactoryPath is apart of.

What is the best way to get the actual Absolute URI then in MVC projects?

You can get the full URL by combining it with the BaseUrl, e.g:

var getUrl = Request.GetBaseUrl().CombineWith(requestDto.ToGetUrl());

Actually this should also be what RequestDto.ToAbsoluteUri() returns which is in the ServiceStack server library. But if this isn’t a classic ASP.NET Web project you’d need to also pass the IRequest as well:

var getUrl = requestDto.ToAbsoluteUri(Request);

requestDto.ToAbsoluteUri() returns https://localhost:44333/requestDtoPath which fails, as the path does not exist. The actual path should be https://localhost:44333/api/requestDtoPath

What ServiceStack Host is this on? E.g classic ASP .NET, .NET Core or Http Listener.

Using AppHostBase within a ASP .NET site (MVC and using a ServiceStackController

I’m not able to reproduce this, I’ve created a new ServiceStack MVC5 project in VS.NET and changed the Hello Service to return the Absolute URI:

public class MyServices : Service
    public object Any(Hello request)
        return new HelloResponse {
            Result = $$"Hello, {request.Name}!",
            AbsoluteUri = request.ToAbsoluteUri()

Which for http://localhost:49928/api/hello.json returns:

  "Result": "Hello, !",
  "AbsoluteUri": "http://localhost:49928/api/hello"

and for http://localhost:49928/api/hello/world.json returns:

  "Result": "Hello, world!",
  "AbsoluteUri": "http://localhost:49928/api/hello/world"

Did you start from one of the templates otherwise did you follow the MVC Integration docs, you can find a working ServiceStack + MVC configuration in the MVC 5 Project Template.

I followed the MVC Integration documents. The problem occurs when accessing a service through a controller, for instance:

public class HelloWorldController : ServiceStackController
     public MyServices MyServices {get;set;}

     public ActionResult Hello()
          return View(new Hello().ToAbsoluteUri());

ok it’s trying to resolve the BaseUrl from the incoming request URL which wasn’t a ServiceStack Request, but it should be resolved from this commit.

This change is available from the latest v5.5.1 that’s now available on MyGet.

Alternatively you can specify the Config.WebHostUrl where it will use that instead, e.g:

SetConfig(new HostConfig {
    WebHostUrl = "https://localhost:44333/api"