VirtualPathProvider Extensibility in ASP.NET 2.0

One of the really powerful things we did in ASP.NET 2.0 was to build a pluggable provider abstraction for a web app’s file activity, and to then re-plumb the ASP.NET parser, compiler, and other path/content/page related work to go through it.  What this ends up delivering is a lot of extensibility capabilities not possible in ASP.NET V1.1.

 

Some examples of what you could do:

 

1) Re-plumb the storage of a web-site from being the file-system to instead have all content stored in a database or some other store (btw -- the next version of SharePoint is using this mechanism to-do this).

 

2) Hook and modify path information, and plug into the compilation process of the web-site.

 

3) Perform richer validation analysis on content being parsed (for example: disallowing certain controls from being used if you want to lock down and only allow “safe” controls on a site).

 

David Ebbo just started a blog to share some of the ideas of what you could do with this support.  His first post answers a question from someone in a forum who wanted to find a way to create multiple “virtual sites” within a single ASP.NET application and app-domain.  David shares how this can be done with only a few lines of code.

 

Definitely a great blog to keep an eye on!

 

- Scott

 

Published Sunday, November 27, 2005 9:30 PM by ScottGu

Comments

# re: VirtualPathProvider Extensibility in ASP.NET 2.0

Monday, November 28, 2005 7:28 AM by Mark A. Richman
How about a virtual metabase provider so I can use shared storage such as SQL 2005 or even AD as my IIS configuration store instead of that nasty metabase.xml file :)

# re: VirtualPathProvider Extensibility in ASP.NET 2.0

Monday, November 28, 2005 10:47 AM by scottgu
Hi Mark,

In IIS7 we are actually doing away with metabase.xml entirely, and moving IIS to use the same web.config based configuration model that ASP.NET uses (we are also adding a number of new features). This should hopefully make configuration much easier...

Thanks,

Scott

# re: VirtualPathProvider Extensibility in ASP.NET 2.0

Monday, November 28, 2005 8:50 PM by Mark A. Richman
Scott,

Will multiple IIS machines be able to share that new .config via, say, CIFS?

- Mark

# re: VirtualPathProvider Extensibility in ASP.NET 2.0

Monday, November 28, 2005 9:50 PM by scottgu
Hi Mark,

That is a scenario we are looking to enable. You can now distribute app and site level .config files on a central file-server and have multiple front-end boxes pick it up.

We are still working on getting the top-level .config files (that define app-pools and site bindings) to support centralized storage (this part isn't implemented yet). Once we have that working, you should be able to have totally stateless front-end boxes that pull all code + content + config from central stores.

Hope this helps,

Scott

# re: VirtualPathProvider Extensibility in ASP.NET 2.0

Tuesday, November 29, 2005 6:28 AM by Mark A. Richman
Scott,

That's great news! Will there be a managed API to handle all this as well so I can dump my old WMI/ADSI libraries?

- Mark

# re: VirtualPathProvider Extensibility in ASP.NET 2.0

Tuesday, November 29, 2005 7:21 AM by Erling Paulsen
Hi Scott,
does the VirtualPathProvider work with all file extensions, or only file types mapped to the Asp.Net runtime(e.g. *.aspx, *.ascx etc.)?

This kind of functionality would be great for the document database of our CMS system, but not if I have to manually map all file extensions to the Asp.Net runtime...

# re: VirtualPathProvider Extensibility in ASP.NET 2.0

Friday, December 2, 2005 3:47 AM by scottgu
Hi Mark,

Yep -- there will be a managed API for you to use, along with some great command-line utilities that are very rich and extensible.

Thanks,

Scott

# re: VirtualPathProvider Extensibility in ASP.NET 2.0

Friday, December 2, 2005 3:48 AM by scottgu
Hi Erling,

The VirtualPathProvider in ASP.NET V2.0 only works with those file extensions that have been mapped to ASP.NET.

One of the things in ASP.NET 2.0 for Windows Server 2003 and IIS6, though, is the ability for ASP.NET to handle * scriptmappings much more efficiently than past releases. You can now do * script-mapping and not have perf completely tank or files like .asp pages break.

Hope this helps,

Scott

# re: VirtualPathProvider Extensibility in ASP.NET 2.0

Monday, December 5, 2005 11:08 PM by scottgu
Hi Mark,

You will be able to declaratively specify app pools and approots. You won't be able to-do that within your's app's web.config file, though, for security reasons (since you really want the parent of that app to configure those).

You will be able to specify other settings though (authentication, directory browsing, cache headers, comrpession, etc) in the web.config file.

Hope this helps,

Scott

# re: VirtualPathProvider Extensibility in ASP.NET 2.0

Saturday, December 17, 2005 6:44 PM by MS
I am having a problem with this change...
we have all our .ascx as embedded resource in the dll which when retrieved and parsed causes the TemplateControl's ParseControl method to throw ArgumentNullException on virtualpath parameter. This worked fine in v1.1. Is there an alternative?

# re: VirtualPathProvider Extensibility in ASP.NET 2.0

Tuesday, December 20, 2005 2:27 AM by scottgu
Hi MS,

Any chance you could send me an email describing this scenario more (scottgu@microsoft.com). I can then help come up with a solution for you.

Thanks,

Scott

# re: VirtualPathProvider Extensibility in ASP.NET 2.0

Tuesday, September 12, 2006 7:01 AM by Brad Vincent
Hey Scott, What i am trying to do is the following: load a string of text out my DB that represents a page of HTML. (This is for a basic CMS system). In that html i want to allow for some asp.net syntax like . How can i load it and then 'compile' the code and output the intended html? thanks!

# re: VirtualPathProvider Extensibility in ASP.NET 2.0

Tuesday, September 12, 2006 10:18 AM by ScottGu

Hi Brad,

The VirtualPathProvider is the way to go.  It allows you to store any HTML (with or without server controls in it), and then run it through ASP.NET.

The code sample above should help get you started on how to-do this.

Thanks,

Scott

# re: VirtualPathProvider Extensibility in ASP.NET 2.0

Tuesday, November 7, 2006 2:30 PM by Constantin
Scott, VPP is a good thing, but why is it not gonna to be registered on IIS application start up (Initialize method is not called)? Neither on a fresh installed 2003 Web Edition nor XP Pro. I mean just a code from MSDN VPP class example. Though under VS server it is running OK. Are there some hidden tricks? Thanks, Constantin

# re: VirtualPathProvider Extensibility in ASP.NET 2.0

Thursday, November 9, 2006 12:00 AM by ScottGu

Hi Constantin,

I'm not sure why you are running into that.  Can you send me email with the details?  I can then loop someone in to help.

Thanks,

Scott

# re: VirtualPathProvider Extensibility in ASP.NET 2.0

Wednesday, December 6, 2006 12:14 AM by ScottGu

Hi DavidW,

Can you send me an email (scottgu@microsoft.com) with this question?

I will then loop in someone from my team who can help.

Thanks,

Scott