更改静态内容的虚拟路径 [英] Change the virtual path for static content

查看:76
本文介绍了更改静态内容的虚拟路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在一个项目上,该项目是一个托管2个单独的插件"的自托管服务堆栈站点.我正在尝试进行设置,以便可以从插件目录中提供静态内容文件,以便在调试时可以即时对其进行编辑,而无需进行重新构建即可将更改内容复制到bin目录中.

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") });

我似乎无法弄清楚如何对我的静态内容文件执行相同的操作.似乎可以通过添加EndpointHostConfig.Instance.WebHostPhysicalPath = "../../../ProjectName";来一次修复一个项目,但不能同时修复两个项目吗?有没有一种方法可以为所有服务的文件设置虚拟路径提供程序,而不仅仅是剃刀文件?

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?

推荐答案

ServiceStack尚未切换为使用VirtualPathProvider处理静态文件内容.

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

确定静态文件的请求发生在ASP.NET请求管道的开始时(即在到达ServiceStack的IHttpHandler之前),此时解决VirtualPathProvider并不理想(即耦合).

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).

我们目前正在研究使用虚拟路径的后果,因为它会使主机Web服务器期望的物理路径无效.

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.

ServiceStack的操作顺序中的前两个挂钩可让您注入自定义逻辑并处理静态文件请求以覆盖ServiceStack的默认行为,二者都可以在AppHost.Configure()中配置,并且在两种情况下,如果您想劫持请求,都可以返回IHttpHandler:

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:

1) Config.RawHttpHandlers:

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

2)IAppHost.CatchAllHandlers:

2) IAppHost.CatchAllHandlers:

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

这篇关于更改静态内容的虚拟路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆