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:
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.
If I run using WebDev in Visual Studio instead of IIS, the virtual gif files render fine.
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.
...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...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With