ASP.NET VirtualPathProvider 与静态文件问题

发布于 2024-11-28 14:49:50 字数 653 浏览 6 评论 0原文

我在 Windows 7 上运行 IIS 7.5。我的 ASP .NET 应用程序使用 VirtualPathProvider。大多数文件(aspx 页面)都由我的 VirtualPathProvider 返回并呈现良好。静态文件(css/图像)不是。如果我尝试直接浏览它们(或者它们被我的虚拟 aspx 页面引用),它们会产生 HTTP 404 错误。

我已经验证了我的 web.config 已为静态文件类型注册了正确的处理程序。

奇怪的是:

  1. 如果我尝试浏览到一个非虚拟 gif 文件(实际存在于网站根目录下的文件系统中的文件),它会呈现正常。

  2. 如果我在 Visual Studio 中而不是 IIS 中使用 WebDev 运行,则虚拟 gif 文件呈现良好。

  3. 在调试模式下,在VirtualPathProvider.GetFile中,我可以看到我的VirtualPathProvider在页面返回404错误之前返回了虚拟gif文件的完全有效的实例...所以我知道我的VirtualPathProvider工作正常。

注意,当我说 IIS 时,我并不是指在已部署的环境中。我只是说将项目设置切换为使用 IIS 而不是 WebDev。

有什么想法吗?

谢谢。

I'm running IIS 7.5 on Windows 7. My ASP .NET application uses a VirtualPathProvider. Most of the files (aspx pages) are returned and rendered fine by my VirtualPathProvider. Static files (css/images) are not. They yield a HTTP 404 error if I try to browse to them directly (or if they're referenced by my virtual aspx page)

I've verified my web.config has the correct handler registered for static file types.

What's weird is this:

  1. If I try to browse to a non-virtual gif file (one that actually exists on the file system under the website root), it renders fine.

  2. If I run using WebDev in Visual Studio instead of IIS, the virtual gif files render fine.

  3. In debug mode, in VirtualPathProvider.GetFile, I can SEE my VirtualPathProvider returning a perfectly valid instance of my virtual gif file right before the page returns the 404 error...so I know my VirtualPathProvider is working just fine.

NOTE, when I say IIS, I don't mean in a deployed environment. I just mean switching the project settings to use IIS instead of WebDev.

Any ideas?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦初启 2024-12-05 14:49:50

...和 ​​答案

我遇到的问题,特别是在显示路由时,即使使用到 ASP.NET 的通配符映射,我的静态文件最终也会出现 404 错误代码,因为路由正在捕获它们并发送请求到 MVC 处理程序,但未找到路由。失败。

因此,作为对我自己(以及其他正在做类似事情的人)的说明,我发现您需要执行以下操作才能让您的 VPP 提供静态文件。

首先,您需要将所需的静态文件类型映射到 ASP.NET...

...and answer:

The problem I’ve run into a bunch, particularly with routing showing up, is that even with a wildcard map to ASP.NET, my static files end up with a 404 error code because routing is catching them, sending the requests to the MVC handler, and no route is found. Fail.

So, as a note to myself (and anyone else who’s doing something similar), here’s what I’ve found you need to do to get your VPP serving up static files.

First, you need to get the desired static file types mapped to ASP.NET...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文