Change the virtual path for static content

女生的网名这么多〃 提交于 2019-12-11 09:18:38

问题


I'm working on a project that is a self hosted service stack site hosting 2 separate "Plugins". I am trying to set it up so that I can serve up my static content files from the plugin directories so that I can edit them on the fly while debugging and not require a rebuild to copy the chages to the bin directory.

I already have this working for the my razor files by adding this:

Plugins.Add(new RazorFormat { VirtualPathProvider = new FileSystemVirtualPathProvider(this, "../../../Project1") });
Plugins.Add(new RazorFormat { VirtualPathProvider = new FileSystemVirtualPathProvider(this, "../../../Project2") });

I cant seem to figure out how to do the same for my static content files. It seems that I could fix one project at a time by adding EndpointHostConfig.Instance.WebHostPhysicalPath = "../../../ProjectName"; but not both at the same time? Is there a way to set the virtual path provider for all files served and not just razor files?


回答1:


ServiceStack has not switched over to use the VirtualPathProvider to handle static files contents.

Determining a request for a static file happens at the start of the ASP.NET request pipeline (i.e. before it reaches ServiceStack's IHttpHandler's) at a point where resolving a VirtualPathProvider is not ideal (i.e coupling).

We're currently investigating the consequences of using a virtual path since it invalidates the physical path that's expected by the host web server.

Overriding ServiceStack's default behaviour

The first 2 hooks in ServiceStack's Order of operations allow you to inject custom logic and handle static file requests to override ServiceStack's default behavior, both are configurable in AppHost.Configure() and in both cases you can return an IHttpHandler if you want to hi-jack the request:

1) Config.RawHttpHandlers:

SetConfig(new EndpointHostConfig { 
    RawHttpHandlers = { (httpReq) => ... },
});

2) IAppHost.CatchAllHandlers:

this.CatchAllHandlers.Add((httpMethod, pathInfo, filePath) => ...);


来源:https://stackoverflow.com/questions/14964764/change-the-virtual-path-for-static-content

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!