views:

139

answers:

1

Hi,

I can create a page from a file with:

Page page = BuildManager.CreateInstanceFromVirtualPath(
    virtualPath, typeof(Page)) as Page;

How can I instantiate a page from a stream or a string?

Thank you.

+6  A: 

You can create your own VirtualPathProvider, which sits between the ASP.NET parser and the file system. The default provider in ASP.NET reads ASPX markup from disk, but you can create your own to read it from anywhere (SQL, a stream, a string, etc).

Essentially how it works is that the custom VirtualPathProvider class takes over the handling of virtual paths like "~/MyPage.aspx" (which you must pass in to the BuildManager). It provides custom logic for deciding what to do with "~/MyPage.aspx", which could include returning data stored in a string or stream in memory.

Here's some reading to get you started:

Rex M
Great info, thanks!
Dawkins