I'm developing a REST api using ServiceStack and have trouble with the default redirect to the metadata page. I have published the service to virtual folder "myservice" on a public IIS7 server.
URL "http://mydomain/myservice/whatever" works as designed and "http://mydomain/myservice/metadata" displays the metadata page (with correct link urls).
The trouble is, when accessing "http://mydomain/myservice" it redirects to "http://localhost/myservice/metadata", not "http://mydomain/myservice/metadata".
How do I configure the metadata url?
In ServiceStack you can specify what baseUrl to use for all redirects by specifying it in the AppHost.Configure()
:
SetConfig(new HostConfig {
WebHostUrl = "http://mydomain/",
});
You can override how ServiceStack resolves Absolute Url's by overriding ResolveAbsoluteUrl()
in your AppHost, e.g:
public class AppHost : AppHostBase
{
//...
public override string ResolveAbsoluteUrl(string virtualPath, IRequest req)
{
virtualPath = virtualPath.SanitizedVirtualPath();
return req.GetAbsoluteUrl(virtualPath);
}
}
Old question but I got this issue too and found the solution here.
Basically, if you deploy your service somewhere and on the same machine you open the metadata page in the browser, using the ´http://localhost:XXXX/metadata´ URL, ServiceStack will remember this until the service restarts and will keep redirecting to this URL no matter from where you are trying to open this page.
So, restart the service and open the metadata page using its remote address and it should be fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With