weixin_39738380
weixin_39738380
2020-12-26 00:45

Kestrel return 404 when is run as a windows service

Hi I'm having trouble with running my asp.net core 1.1 application as a windows service (I'm using dot.net framework 4.6.2). My setup code looks as follows:

csharp
Directory.SetCurrentDirectory(System.AppDomain.CurrentDomain.BaseDirectory);
 var host = new WebHostBuilder()
               .UseKestrel()
               .UseUrls("http://*:5000")               
               .UseContentRoot(Directory.GetCurrentDirectory())
               .UseIISIntegration()
               .UseStartup<startup>()               
               .Build();
 host.RunAsService();
</startup>

after installing my application as as a windows service (with sc create command) I'm getting 404 when requesting http://localhost:5000 address. The service is running and the response contains header "Server: Kestrel". When I run my application as a regular console app (using host.Run() instead of host.RunAsService()) everything works as it should (http://localhost:5000 return my page) What am I missing here? How to make my application work as a windows service?

该提问来源于开源项目:aspnet/Hosting

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

4条回答

  • weixin_39528843 weixin_39528843 4月前

    The doc for this is almost ready. Your content root is most likely wrong. https://github.com/aspnet/Docs/pull/3060/files#diff-3a33a1126f222fba5d3dac1f77cf8da5R42

    点赞 评论 复制链接分享
  • weixin_39738380 weixin_39738380 4月前

    I'm not convinced that the path is the problem. I attached debugger and check that it's ok (I've used also code from the link you provided and there is no difference in result). How can I diagnose that the path is really a culprit?

    点赞 评论 复制链接分享
  • weixin_39729837 weixin_39729837 4月前

    You first step to diagnosing anything would be to enable logging. It should tell you exactly what's wrong.

    点赞 评论 复制链接分享
  • weixin_39781550 weixin_39781550 4月前

    Closing this one. Please file another bug if you still have issues.

    点赞 评论 复制链接分享

相关推荐