问题描述
我使用的是 ServiceStack 4.0.17 并且 Host.Instance.Config.WebHostUrl
始终为空.
I'm using ServiceStack 4.0.17 and the Host.Instance.Config.WebHostUrl
is always null.
我使用 ServiceStack 作为独立的 Web 应用程序 - 没有 MVC 或 ASP.NET - 由 IIS Express (VS2013) 在集成模式下提供服务.
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.
是否有任何必需的配置来将 ServiceStack 作为我可能缺少的独立 Web 应用程序运行?
Is there any required configuration to run ServiceStack as a standalone web application that I may be missing?
如果有人遇到同样的问题,我创建了一个可以在 Application_BeginRequest 中使用的临时解决方法:
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;
}
}
}
推荐答案
所有 ServiceStack 配置都应在 AppHost.Configure()
中使用 SetConfig 方法进行设置,例如:
All ServiceStack configuration should be set in the AppHost.Configure()
with the SetConfig method, e.g:
SetConfig(new HostConfig {
WebHostUrl = myBaseUrl
});
这篇关于如何在 ServiceStack 中设置 WebHostUrl?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!