Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Incorrect default URL to ServiceStack metadata page

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?

like image 465
Fredrik Avatar asked Jan 25 '13 11:01

Fredrik


2 Answers

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/",
});

Overriding Resolved URL's

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);
    }
}
like image 191
mythz Avatar answered Jan 01 '23 23:01

mythz


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.

like image 25
Alexey Zimarev Avatar answered Jan 01 '23 21:01

Alexey Zimarev