IIS 6 上的 VirtualPathProvider 无法正确处理文件流缓存
我正在开发一个框架,其中 .aspx 和 .master 页面嵌入在程序集中,使用 VirtualPathProvider 将 url 路由到特定的嵌入资源。
示例 url:/_framework.aspx/mypage.aspx(使用 /_framework.aspx/mymaster.master)
- _framework.aspx 将使 IIS6
- 在 .aspx 被视为 .aspx 文件中的 PathInfo 之后,通过 ASP.NET 框架路由请求。 NET Framework
在 Visual Studio 2008 Web 服务器中,虚拟路径正确:/_framework.aspx/mypage.aspx 但在 IIS6 中,virtualPath 是: /_framework.aspx
如果我请求两个文件: /_framework.aspx/file1.css 和 /_framework.aspx/file2.css file2 将具有与 file1 相同的内容。
我怀疑 IIS6 会考虑文件路径 (_framework.aspx) 并缓存从程序集返回的文件流,从而将两个 url 视为同一文件。
临时解决方案:
我已经实现了这样的 CacheDependency 类,
class ImmediateExpiryCacheDependency : System.Web.Caching.CacheDependency
{
public ImmediateExpiryCacheDependency()
{
base.NotifyDependencyChanged(null, null);
}
}
它现在使文件流缓存过期,但不适用于母版页,我猜是因为它是在缓存过期之前通过 NotifyDependencyChanged 请求的。
所需的解决方案:
如果我在 GetCacheDependency 中返回 null,IIS6 不会立即使文件过期。立即使文件过期或完全禁用缓存的正确方法是什么?更好的是,我想纠正 IIS6 处理 url 的方式,因为如果它使用完整的文件 url,缓存实际上很好。
I am working on a framework where .aspx and .master pages are embedded in an assembly, using VirtualPathProvider to route a url to a specific embedded resource.
Sample url: /_framework.aspx/mypage.aspx (which uses /_framework.aspx/mymaster.master)
- _framework.aspx will make IIS6 route the request through ASP.NET framework
- everything after the .aspx is treated as a PathInfo in the .NET framework
In Visual Studio 2008 web server, the virtualPath is correctly: /_framework.aspx/mypage.aspx
but in IIS6 the virtualPath is: /_framework.aspx
If I request two files: /_framework.aspx/file1.css and /_framework.aspx/file2.css
the file2 will have the same content as file1.
I suspect that IIS6 considers the file path (_framework.aspx) and caches the file stream which is returned from the assembly, thus treating both urls as the same file.
Temporary solution:
I've implemented a CacheDependency class like this
class ImmediateExpiryCacheDependency : System.Web.Caching.CacheDependency
{
public ImmediateExpiryCacheDependency()
{
base.NotifyDependencyChanged(null, null);
}
}
It now expires the file stream cache, but doens't work with master pages, I guess because it is requested before the cache is expired through NotifyDependencyChanged.
Needed solution:
If I returned null in GetCacheDependency, IIS6 doesn't expire the file immediately. What is the correct way to immediately expire a file or disable the caching entirely. Even better, I would like to correct the way that IIS6 deals with the url, since the caching is actually good, if it would use the full file url.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通过我在 ASP.NET 开发 Web 服务器中的工作,我得出结论,正确的 FilePath 将包含 PathInfo,但我现在明白 IIS 实现是正确的。
我更改了代码,以便 ASP.NET 文件(aspx、ashx)具有诸如 /_framework/Default.aspx 之类的路径(因为这些文件将在没有特殊配置的情况下进行路由)以及诸如 /_framework/Site 之类的母版页路径。 master(因为这是在 ASP.NET 引擎内部路由的)以及路径为 /_framework.ashx/image.gif 的图像资源(因为 .ashx 将被路由到 ASP.NET 引擎,然后我将在其中使用一种 StaticFileHandler)。
这样,所有页面和资源都可以完全驻留在程序集中:-)
Through my work in the ASP.NET Development Web Server, I had come to conclude that the correct FilePath would include the PathInfo, but I understand now that the IIS implementation is correct.
I changed my code so that ASP.NET files (aspx, ashx) would have a path such as /_framework/Default.aspx (since these files will be routed without special configuration) with a master page path such as /_framework/Site.master (since this is routed internally in the ASP.NET engine) and with image resources with a path /_framework.ashx/image.gif (since the .ashx will be routed to the ASP.NET engine, from where I will then use a kind of StaticFileHandler).
This way, all pages and resources can reside and remain entirely in the assembly :-)