几周前我问了一个关于这个的问题,在这里找到:ServiceStack: URL Re-writing with Self-Hosted application
但是,当我将此应用程序创建为 Windows 服务时遇到了问题。浏览应用程序的根 URL 时出现以下错误:
error CodeFileNotFoundExceptionmessage
Could not find file 'C:\Windows\system32\index.html'.
这是我所做的:
var handleRoot = new CustomActionHandler((httpReq, httpRes) =>
{
httpRes.ContentType = "text/html";
httpRes.WriteFile("index.html");
httpRes.End();
});
SetConfig(new EndpointHostConfig
{
DebugMode = false,
RawHttpHandlers =
{
httpReq => (httpReq.RawUrl == "/") ? handleRoot : null
}
});
public class CustomActionHandler : IServiceStackHttpHandler, IHttpHandler
{
public Action<IHttpRequest, IHttpResponse> Action { get; set; }
public CustomActionHandler(Action<IHttpRequest, IHttpResponse> action)
{
if (action == null)
throw new Exception("Action was not supplied to ActionHandler");
Action = action;
}
public void ProcessRequest(IHttpRequest httpReq, IHttpResponse httpRes, string operationName)
{
Action(httpReq, httpRes);
}
public void ProcessRequest(HttpContext context)
{
ProcessRequest(context.Request.ToRequest(GetType().Name),
context.Response.ToResponse(),
GetType().Name);
}
public bool IsReusable
{
get { return false; }
}
}
如果我把它拿出来并浏览我的服务的根目录,它可以工作,但我已经/index.html
附加到最后,因为我希望它就像我将它/
作为控制台应用程序托管时一样