Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET VirtualPathProvider with Static Files Issue

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.

like image 925
Jeff Avatar asked Aug 07 '11 19:08

Jeff


1 Answers

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

like image 195
Jeff Avatar answered Nov 13 '22 00:11

Jeff