I would combat this issue by checking for the prefix in the ServiceStack AppHost config. From the v3 documentation:
In order to avoid conflicts with your existing ASP.NET web framework it is recommended to host your ServiceStack web services at a custom path. ...
The location configuration (to your root Web.config file)
belowhosts your webservices at custom path:/api
...
You also need to configure the root path in your AppHost.
So because ServiceStack expects you to configure it with the matching path like this in the AppHost:
public override void Configure(Container container)
{
SetConfig(new EndpointHostConfig { ServiceStackHandlerFactoryPath = "api" });
}
You can access the value directly from ServiceStack's config.
In v3 it can be accessed from the Service
using:
GetAppHost().Config.ServiceStackHandlerFactoryPath
In v4 you can use:
AppHost.Instance.Config.WebHostUrl
Obviously it would be handy if the UrlExtensions ToUrl()
method already performed this check and prefixed accordingly.
As @esker notes the path will not include the leading slash, so it must be prefixed with /
to be a valid static path.