tags:

views:

78

answers:

3

Hi All,

I have a IHttpModule to serve up .aspx page dynamically, this is so I can pack them into a DLL and drop it into an existing web site and serve up my pages.

I have a class MyPage derived from System.Web.UI.Page which has a .aspx, .aspx.cs and a aspx.designer.cs file.

When I try to instantiate the class I.e. MyPage myNewPage = MyPage(), all of the child controls are null...

I then attempt to render that page output using Server.Execute(myNewPage) in the BeginRequest event of the IHttpModule.

I know I can compile the page and use reflector to get the compiled class that's built out, but is there a cleaner way to do this?

Or even a better approach to what I'm doing?

Thanks, Goosey

A: 

I don't think this is possible. You cannot just instantiate page like any other object. What you need "might" be a VirtualPathProvider.

epitka
A: 

I'm not sure it's the best solution, but you can embed all the aspx pages into your dll as assets. On request extract the aspx from the embedded resource and write to disk (if it hasn't already happened).

There may be a way to provide the aspx from the embedded resource without actually writing to disk, but I don't know for sure.

Sam
A: 

aspx has some intimate relationship with ASP.NET runtime. I do not think that instantiating it bu just calling constructor is a good idea. What you can do instead is to have an empty (standard) aspx and move your code to user controls - ascx

Those you can load dynamically using LoadControl method

mfeingold
Thanks for the response.I was actually hoping for something very similar to LoadControl, but for a page.I will probably end up going this route, I was just hoping for a cleaner and easier solution.
Goosey