Change the virtual path for static content
Asked Answered
T

1

1

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?

Tureen answered 19/2, 2013 at 18:28 Comment(0)
W
2

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) => ...);
Wantage answered 20/2, 2013 at 8:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.