我试图在Topshelf服务中使用Nancy(使用Razor查看nuget包的Self Hosting).我在http:// localhost:8585 /上托管它,它在我处于调试模式或直接调用我的可执行文件时工作正常.Nancy模块完美地提供了剃刀视图.
然后我安装应用程序:
myapp.exe install
Run Code Online (Sandbox Code Playgroud)
当我启动服务时,似乎工作正常,并且没有错误.然后,当我在浏览器中访问http:// localhost:8585 /时,我得到一个空白的回复.任何想法为什么?
在我开始使用Topshelf托管服务之前,我启动Nancy:
_nancyHost = new NancyHost(_baseUri);
_nancyHost.Start();
Run Code Online (Sandbox Code Playgroud)
之后,topshelf服务配置并启动如下:
using (Container)
{
var host = HostFactory.New(config =>
{
config.EnableDashboard();
config.AfterStartingServices(() => Console.WriteLine("Done starting..."));
config.Service<EventHandlerService>(s =>
{
s.SetServiceName("EventHandlerService");
s.ConstructUsing(c => Container.Get<EventHandlerService>());
s.WhenStarted(n => StartService(n, stopwatch));
s.WhenStopped(n => StopService(n, stopwatch));
});
config.RunAsLocalSystem();
config.SetDescription("A service for processing events.");
config.SetDisplayName("EventHandlerService");
config.SetInstanceName("EventHandlerService");
config.SetServiceName("EventHandlerService");
});
host.Run();
}
Run Code Online (Sandbox Code Playgroud)
我使用的是ninject,StartService和StopService方法只是打印stopwatch.ElapsedMilliseconds当前值的函数.
这是我的Nancy模块的配置:
Get["/"] = parameters =>
{
var indexViewModel = new IndexViewModel { CurrentDateTime = DateTime.Now, WorkLog = _service.WorkLog };
return View["index", indexViewModel];
};
Get["/js/{file}"] = p =>
{
return Response.AsJs("scripts/" + p.file as String);
};
Get["/style/{file}"] = p =>
{
return Response.AsCss("content/themes/base/" + p.file as String);
};
Get["/img/{file}"] = p =>
{
return Response.AsImage("content/themes/base/images/" + p.file as String);
};
Run Code Online (Sandbox Code Playgroud)
我正在使用Nancy中的所有默认设置,而不是Self Hosting和Razor部件.知道可能会发生什么吗?
我也试过netsh http add urlacl url=http://+:8585/ user=\Everyone,似乎没有对行为产生任何影响.
我猜测它是一个根路径问题,所以它无法找到你的视图(假设正在复制视图).我不知道TopShelf是如何工作的 - 它是否将工作目录设置为它正在启动的应用程序的目录?默认情况下,根路径将设置为"Environment.CurrentDirectory",这可能是也可能不正确.
如果使用CurrentDirectory不可行,那么您可以切换到嵌入式视图(如何在主解决方案中执行此操作的示例),或者将IRootPathProvider的实现添加到项目中并返回组装位置(它将自动拾取您的版本超过默认值)
| 归档时间: |
|
| 查看次数: |
1904 次 |
| 最近记录: |