Listen on multiple paths

How can I listen on multiple paths?

Ex: http:///Test1 and http:///Test2

When I add second address the first address becomes case sensitive and also second one doesn’t work.

You can supply multiple url prefixes which will start the HTTP Listener listening on multiple prefixes, e.g:

new AppHost()
    .Start(new[]{ "http://*/Test1/", "http://*/Test2/" });

But ServiceStack wasn’t designed for multiple HTTP endpoints, e.g. you can only configure 1 BaseUrl, so you’ll likely want to override AppHost.GetBaseUrl() to return the correct BaseUrl for the different requests from each endpoint.

Looks like GetBaseUrl method doesn’t get called when I override it. Am I missing something?

It should get called when it’s needed to construct an Absolute Url e.g. when you call the /metadata pages.

The issue with having multiple url-prefixes with different paths, e.g. http://*/Test1/ and http://*/Test2/ is that the first url is used to determine what the Config.HandlerFactoryPath path is e.g. Test1 which is used to determine what the path info is for the request which is why it works for the first url prefix and not the second one.

You can listen on different ports as they’ll both have the same null HandlerFactoryPath, e.g:

new AppHost()
    .Start(new[]{ "http://*:8080/", "http://*:8081/" });

But you wont be able to host with different paths.

My main goal here is that if user goes to http:///Test2, I can redirect them to http:///Test1 instead. Is there any other way to achieve that?

Sure you can listen on both prefixes then add a RawHttpHandler that automatically detects urls to /Test2/* and redirects them to /Test1/* in your AppHost.Configure() with something like:

RawHttpHandlers.Add(req => req.PathInfo.StartsWith("/Test2")
    ? new RedirectHttpHandler {AbsoluteUrl = req.AbsoluteUri.Replace("Test2","Test1")}
    : null);

But note when you’re using a listener prefix with a path suffix e.g. http://*/Test1/ instead of http://*/ you’re saying ServiceStack is only hosted from that path which may or may not be what you want.