Custom PageHandler ???

C

Chris

Hi,

I have 2 pages: IntPage.aspx and StringPage.aspx with the classes
declared in their respective code behind files.
Both pages are declared in the root folder and work fine

Then I have a CustomPageHandlerFactory class (declared in the App_Code
folder):

public class MyPageHandlerFactory : PageHandlerFactory
{
public override IHttpHandler GetHandler(HttpContext context,
string requestType, string virtualPath, string path)
{
IHttpHandler myhandler = null;

if (some boolean condition)
myhandler = new IntPage();
else
myhandler = new StringPage();
return myhandler;
}
} // class MyPageHandlerFactory

But I get a compiler error on IntPage and StringPage -->
"The type or namespace name 'IntPage' could not be found"
"The type or namespace name 'StringPage' could not be found"

It seems to me that, from a page class you can use any class declared
in the App_Code folder but not the other way around.

How can this be solved ?

thx
Chris
 
B

bruce barker

the pages are compiled separately into their own dll(s), so they are not
known when the appcode is compiled. you need to do this lookup at runtime:

var type = BuildManager.GetCompiledPageType(pagePath);
var myhandler = Activator.CreateInstance(type) as IHttpHandler;

-- bruce (sqlwork.com)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,222
Members
46,810
Latest member
Kassie0918

Latest Threads

Top