When using ServiceStack 5.5 with MVC 5.2.7.0, the RequestDto.ToAbsoluteUri() returns a URL without the HostConfig.HandlerFactoryPath. What am I doing wrong?
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.
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:
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:
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());
}
}