I can only serve one file using OWIN UseStaticFiles

I am using OWIN to serve static content via http from a windows service. (To integrate the web administration tool for the Windows service).

I experience strange behavior:

  • When the service starts, I can access only one file located in the "web" folder, each successive call leads to the browser indicating that the page is inaccessible (ERR_CONNECTION_RESET).
  • Embedded WebApi remains available .
  • When I restart the service with the same address and port, the files remain invisible.
  • When I restart the service on another port, I can access the file once ...

By the way, these files in this "Internet" folder are set to "Always copy" for the "Copy to output directory" property.

Does anyone know what is going wrong?

See here my StartUp configuration class

public class WebStartUp { public void Configuration(IAppBuilder app) { string staticFilesDir = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "web"); app.UseStaticFiles(staticFilesDir); HttpConfiguration config = new HttpConfiguration(); config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); app.UseWebApi(config); } } 

See here my windows service which hosts it ...

  public partial class MyService : ServiceBase { private IDisposable webApp; private const string ServiceAddress = "http://localhost:2345"; public MyService() { } protected override void OnStart(string[] args) { InternalStart(); } internal void InternalStart() { webApp = WebApp.Start<WebStartUp>(url: ServiceAddress); } protected override void OnStop() { } public static void Main() { #if DEBUG var service = new MyService(); Console.WriteLine("starting"); service.InternalStart(); Console.ReadLine(); #else ServiceBase[] ServicesToRun; ServicesToRun = new ServiceBase[] { new RaceManagerService(); } ServiceBase.Run(ServicesToRun); #endif } } 
+5
source share
2 answers

I think I know what is going wrong: the third-party framework that you are using is either in alpha or beta. You should not rely on them based on experience with them and their general condition.

I created an almost identical setup ( link to project files ) and saw the exact results. The libraries used just do not cope with the task.

Edit:

I could make it work much more efficiently with version 0.23.20815.0 from the Microsoft.Owin.StaticFiles library. I built it myself from the latest sources of Katana. You can find my latest code on my GitHub page .

+2
source

I use a similar configuration: Windows service as an OWIN host with WebApi and StaticFiles. I have never seen your problem with this. It works great.

I am using StaticFiles version 0.24.0-pre-20624-416 from Katana Nightly Builds. Perhaps this will solve your problem. Another difference is that I only configure StaticFiles with a relative path, and not with an absolute path like you. It shouldn't matter, but who knows?

BTW: I wrote about StaticFiles 2 months ago: http://ritzlgrmft.blogspot.de/2013/06/owin-with-static-files-exception.html

0
source

Source: https://habr.com/ru/post/954058/


All Articles