Is there a way to execute a full ASPX source file where the page source is from a string/database/resource and not a file on the file system? It’s straightfoward to render dynamic content/images/etc using HTTP Handlers and Modules and writing to the Response, but there doesn’t seem to be a way to execute/compile ASPX source without a file on the file system. For example:
- HttpContext.Current.Server.Execute() overloads require a path to a file
- System.Web.Compilation.BuildManager can only create from a virtual path
The goal is to be able to execute a string source like the following from a Handler/Module/ViewEngine and not require a file on the file system (but get the source from another location):
<%@ Page language='C#' MasterPageFile='~/Shared/Site.Master' Inherits='System.Web.UI.Page' %> <!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'> <html xmlns='http://www.w3.org/1999/xhtml' > <head id='Head1' runat='server'> <title>ListView Example</title> </head> <body> <form id='form1' runat='server'> <h3>ListView Example</h3> <asp:ListView ID='List' runat='server' DataSourceID='ProductDataSource'> <LayoutTemplate><ol><asp:PlaceHolder runat='server' ID='itemPlaceholder'></asp:PlaceHolder></ol></LayoutTemplate> <ItemTemplate><li><%# Eval('ProductName') %></li></ItemTemplate> </asp:ListView> <asp:AccessDataSource ID='ProductDataSource' runat='server'DataFile='~/App_Data/Northwind.mdb'SelectCommand='SELECT [ProductName], [QuantityPerUnit], [UnitPrice], [CategoryName] FROM [Alphabetical List of Products]'></asp:AccessDataSource> </form> </body> </html>
(NOTE: The sample above is just a simple example, but shows using server controls, data binding syntax, a master page and possible user control declarations in page directives, etc…)
I hope this makes sense!
Perhaps you need a virtual path provider. It allows you to store the ASPX and codebehind in different media – RDBMS, xml file etc.