简体   繁体   English

ASP.NET-aspnet_isapi.dll如何构造页面类

[英]ASP.NET - how does aspnet_isapi.dll construct page class

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. 我们都知道,当收到对abc.aspx的请求时,aspnet_isapi.dll会在其上运行并调用页面的processrequest方法。 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. 好吧,我们所有人都知道ASP.NET运行时会调用处理程序的ProcessRequest来启动进程。 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. 根据页面名称(abc.aspx“,它创建abc类并调用该类的某些方法。现在我要问的是如何创建abc对象。

Here are the stages that occur between receiving a request and sending a response. 这是接收请求和发送响应之间发生的阶段。

在此处输入图片说明

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. 在执行处理程序阶段,在此阶段调用处理程序(范围为URL的模块)以构造响应。 For .aspx files, the PageHandlerFactory handler is used to respond to the request. 对于.aspx文件,PageHandlerFactory处理程序用于响应请求。 For static files, the native-code StaticFileModule module responds to the request. 对于静态文件,本机代码StaticFileModule模块响应该请求。

This is done by the PageHandlerFactory 这是由PageHandlerFactory完成的

The PageHandlerFactory creates instances of classes that inherit from the Page class and implement the IHttpHandler interface. PageHandlerFactory创建从Page类继承并实现IHttpHandler接口的类的实例。 Instances are created dynamically to handle requests for ASP.NET files. 动态创建实例以处理对ASP.NET文件的请求。 The PageHandlerFactory class is the default handler factory implementation for ASP.NET pages. PageHandlerFactory类是ASP.NET页的默认处理程序工厂实现。

The PageHandlerFactory class implements the IHttpHandlerFactory interface to provide the default HTTP handler for ASP.NET files. PageHandlerFactory类实现IHttpHandlerFactory接口以为ASP.NET文件提供默认的HTTP处理程序。 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. 如果需要,PageHandlerFactory调用ASP.NET编译系统进行编译,并返回与URL对应的确切类型,然后创建该类型的实例。 The page type inherits from the Page class and implements the IHttpHandler interface. 页面类型从Page类继承,并实现IHttpHandler接口。

You can try with this code based on HttpContext.Response.Redirect 您可以尝试基于HttpContext.Response.Redirect此代码

public void ProcessRequest(HttpContext context)
{
        context.Response.Write("<H1>This is an HttpHandler Test.</H1>");      
        context.Response.Redirect("YourPage.aspx");
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM