Virtual Path Providers in ASP.NET 2.0

03 April 2007

I ran across something very interesting a couple days ago in ASP.NET 2.0 called the VirtualPathProvider. Essentially, it's some ASP.NET infrastructure that abstracts ASP.NET from using the file system directly, and it allows you to "hook in" to it all and serve pages from something other than the file system.

Because the documentation is a little sparse, and because it looked pretty cool, I dug into it, created a sample, and wrote up a short essay about it. The sample can be downloaded from that page.

I think it has some very interesting possibilities. In particular I'm thinking of using it for the blog to do what most blogging platforms do with url rewriting. Currently the pages are viewed on the site through a generic viewer page with a variable in the query string (which is less cool). This would allow me to do something like /2007/3/15/ThisIsMyBlogPostTitle.aspx.

What I would really like to know is what are the advantages and disadvantages of implementing this with either approach. I see how they're both done, and the the virtual path provider way seems like a cleaner approach. Am I missing something? I know for many, like Community Server, that this would not have been an option when the platform was originally written since this is new in 2.0. But I haven't really heard much of a peep on this thing. Is no one else thinking about it? Are you community server folks thinking about it? Anyway, I would love to hear anyone's thoughts. It seems like a cool technology... 

Comments:9
Comments
  1. Anderson ImesWebsiteon Tue, 03 Apr 2007 11:42:13 GMT

    The VPP has been a big tool I've used in the last couple of months.  It's definitely exciting and has a lot of uses.  It's hard to know when to use URL rewriting vs. the VPP.  I think you can basically break it down like this:

    • Do you need to redirect a user to a page that actually exists on the filesystem, but with specific URL parameters:  URL rewriting
    • Do you need to show the user content that does *not* exist on the file system in a traditional way (i.e. the content is in a database or a zip file, etc): Virtual Path Provider.

    Sometimes you have to use these things in tandem, as well.  It really just depends on your need.

    Hope this helps.

  2. Ericon Wed, 04 Apr 2007 09:23:52 GMT
    Thanks for the comment. After thinking more about it now, that's not quite the distinction I would draw. I went ahead and wrote up a new post about the distinction between the two. Essentially, I'm coming to the point where I think that now that 2.0 is out, they're just technologies that have two completely different functions. Because of the lack of the VPP in 1.x, url rewriting was necessary. Now that VPP arrived, maybe we should make url rewriting just about path rewriting, and not about virtualizing content. Anyway, I write a little more in my more recent post. Thanks for the comment! I'm still thinking through this whole thing in my head...
  3. Anderson ImesWebsiteon Wed, 04 Apr 2007 14:46:38 GMT

    I think that's pretty much what I was saying.  Redirect to a different place: rewriting.  Execute content located somewhere besides the filesystem: VPP.

    Your writeup is very accurate.  Good job.

  4. XanderWebsiteon Tue, 10 Apr 2007 21:50:48 GMT
    One other thing to think about when using a VPP....If the information for loading data in a page is located in the querystring, VPP solutions get *very* expensive in a hurry, because the page for each unique URL that the VPP loads is cached.   So, if you had a blog with twenty posts, and over the course of some period of time, people looked at all twenty posts, you would have twenty seperate pages cached by the VPP, where as with a URL-rewriting scheme, you wouldn't have to cache at all if you didn't want to, and if you did, you could use a far more effiecient scheme.
  5. Ericon Wed, 11 Apr 2007 10:24:04 GMT
    I'm not sure how you could not customize your caching plan using a VPP. VPP's do not automatically do page caching, which means you can do page caching if you want, or just data caching, or a combination of both. What can you do in this respect with url rewriting that you can't do with the VPP?
  6. Victor Mxon Wed, 25 Apr 2007 12:16:03 GMT

    Hi everyone,

    I'm currently chossing between VPP and URL rewriting, but can you help me to choice?.

    I try both of them and this are my experience:

    With URL rewriting, i try it and i have the problem with postbacks, when the user make a postback, the page loaded was the real not the virtual :(

    i.e. the virtual was:   MyApp/hotel/Mexico/FiveStarHotel.aspx
    the same real with query string is MyApp/hotel/info.aspx?hotel=FiveStarHotel.aspx

    I use the tip of replace the Form action direction, but i get a new problem, the relative paths can be resolved because the folder count in my virtual (3) in my real (2)  :( :(  

    With VPP in the same escenario, i can't handle the events of the page because the page it's loaded like file not  an aspx page

    Any suggestion?

    Help me pls

    P.D. Sorry my english are not so good

     

     

     

  7. Ericon Wed, 25 Apr 2007 12:50:43 GMT
    Nothing obvious at the moment. I'd probably need to see the code to really get what the problem is. You can email it to me if you want. I'll take a quick look at it.
  8. Xander Websiteon Mon, 30 Apr 2007 17:27:01 GMT

    >. VPP's do not automatically do page caching, which means you can do page caching if you want, or just data caching, or a combination of both. What can you do in this respect with url rewriting that you can't do with the VPP?  


    They *do* in fact get cached.  Not in the traditional output cache sense, (standard runtime bits all still run, data can be output cached or grabbed fresh or what have you) but the virtual file itself is cached....The equivelent of what would have been the standard ASPX page.

  9. Ericon Tue, 01 May 2007 22:06:54 GMT
    Okay, well that is a difference. Of course I suppose the aspx page you rewrite to would also be cached in the same sense :). Regardless, this is a pretty small difference, unless I'm missing something. But, perhaps a difference nonetheless.
Name:
Blog or Website:
 
Email (will not be displayed):
 
Comment :