Tutorial :Is it possible to create a page from a string in ASP.Net?



Question:

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.


Solution:1

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:


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »