Question

We all know that when a request for abc.aspx is received, the aspnet_isapi.dll works on it and calls the page's processrequest method. My question is how does it create instance of page class and how does it call the page life cycle. Which pattern does it implement?

Well, all of us know that ASP.NET runtime calls the handler's ProcessRequest to start the process. My question is how does it do that. On basis of page name (abc.aspx", it creates that class of abc and calls some methods of that class. Now how does it creates object of abc, is my question.

Was it helpful?

Solution

Here are the stages that occur between receiving a request and sending a response.

enter image description here

This is the application life cycle

The Execute handler stage, where the handler (a module scoped to a URL) is invoked to construct the response. For .aspx files, the PageHandlerFactory handler is used to respond to the request. For static files, the native-code StaticFileModule module responds to the request.

This is done by the PageHandlerFactory

The PageHandlerFactory creates instances of classes that inherit from the Page class and implement the IHttpHandler interface. Instances are created dynamically to handle requests for ASP.NET files. The PageHandlerFactory class is the default handler factory implementation for ASP.NET pages.

The PageHandlerFactory class implements the IHttpHandlerFactory interface to provide the default HTTP handler for ASP.NET files. The PageHandlerFactory calls the ASP.NET compilation system to compile, if necessary, and return the exact type corresponding to the URL, and then creates an instance of that type. The page type inherits from the Page class and implements the IHttpHandler interface.

OTHER TIPS

You can try with this code based on HttpContext.Response.Redirect

public void ProcessRequest(HttpContext context)
{
        context.Response.Write("<H1>This is an HttpHandler Test.</H1>");      
        context.Response.Redirect("YourPage.aspx");
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top