How can I set WebHostUrl in ServiceStack?

假装没事ソ 提交于 2019-12-11 03:55:59

问题


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;
                }
            }
        }

回答1:


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

SetConfig(new HostConfig {
    WebHostUrl = myBaseUrl,
});


来源:https://stackoverflow.com/questions/20061340/how-can-i-set-webhosturl-in-servicestack

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!