2

I'm using ServiceStack 4.0.17 and the Host.Instance.Config.WebHostUrl is always null.

I'm using ServiceStack as a standalone web application - no MVC or ASP.NET - that is being served by IIS Express (VS2013) in integrated mode.

Is there any required configuration to run ServiceStack as a standalone web application that I may be missing?

If someone is having the same issue I created a temporary workaround that can be used in the Application_BeginRequest:

 private void SetApplicationUrl()
        {
            if (_applicationUrl == null)
            {
                lock (_applicationUrlLock)
                {
                    if (ServiceStackHost.Instance.Config.WebHostUrl != null) return;

                    // Remove the page path information.
                    Regex regex = new Regex("(" + HttpContext.Current.Request.Url.AbsolutePath + ")$");

                    _applicationUrl = regex.Replace(HttpContext.Current.Request.Url.AbsoluteUri, string.Empty);

                    ServiceStackHost.Instance.Config.WebHostUrl = _applicationUrl;
                }
            }
        }
Carlos Mendes
  • 1,900
  • 1
  • 18
  • 33

1 Answers1

4

All ServiceStack configuration should be set in the AppHost.Configure() with the SetConfig method, e.g:

SetConfig(new HostConfig {
    WebHostUrl = myBaseUrl
});
J Pollack
  • 2,788
  • 3
  • 29
  • 43
mythz
  • 141,670
  • 29
  • 246
  • 390
  • Thanks. But how can I get my myBaseUrl inside the AppHost.Configure? There's no Request available inside .NET's [Application Start](http://stackoverflow.com/questions/2518057/request-is-not-available-in-this-context) – Carlos Mendes Nov 19 '13 at 03:12
  • It's set once at Application startup, not at runtime. – mythz Nov 19 '13 at 03:16
  • Got it. I thought it could be set at runtime. – Carlos Mendes Nov 19 '13 at 03:29
  • @CarlosMendes Nope but depending what you want to do, you way want to override `ServiceStackHost.ResolveAbsoluteUrl()` in your AppHost class, which gets called whenever ServiceStack want's to resolve a Url. – mythz Nov 19 '13 at 03:40