Our company would like to give a pre-compiled version of our web application to a 3rd party so they can add their own pages and modules to it. In trying to accomplish this, I've so far done the following:
- Compiled our main web app as a Web Deployment Project
- Created a POC web app which references the DLL resulting from step 1 above.
I then added the following static method to our main web app, which should hopefully process requests to its pre-compiled aspx pages:
public static bool TryProcessRequest(HttpContext context)
{
string rawUrl = context.Request.RawUrl;
int aspxIdx = rawUrl.IndexOf(".aspx");
if (aspxIdx > 0)
{
string aspxPagePath = rawUrl.Substring(0, aspxIdx + 5);
string aspxPageClassName = aspxPagePath.Substring(1).Replace('/','_').Replace(".aspx","");
Assembly website = Assembly.GetAssembly(typeof(MCLLogin));
Type pageClass = website.GetType(aspxPageClassName);
ConstructorInfo ctor = pageClass.GetConstructor(new Type[] { });
IHttpHandler pageObj = (IHttpHandler)ctor.Invoke(new object[] { });
context.Server.Execute(pageObj, context.Response.Output, false);
//alternative: invoking the page's ProcessRequest method - same results
//System.Reflection.MethodInfo method = pageClass.GetMethod("ProcessRequest");
//method.Invoke(pageObj, new object[] { context });
return true;
}
return false; //not handled
}
I am then calling this method in the ProcessRequest()
method of a HttpHandler
of the POC web app whenever I want our main web app to handle the request. This code indeed successfully instantiates a page of the correct class and starts to process the request.
The problem:
Code in my Page_PreLoad
handler throws an exception because Page.Form
is null. I've also found out the Page.Controls
collection is empty.
What am I doing wrong? Should I go down a different path to achieve this?