asp.net页面编译过程 [英] asp.net page compilation process

查看:98
本文介绍了asp.net页面编译过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在找对aspx页面和VS2008编译过程的详细技术信息。最近我一直在学习controlbuilders和pageparserfilters。我已经下载了一些code清理在我的html额外的空白,以使页面更小。在code的伟大工程,但我不明白为什么它的工作原理。我需要了解更多有关该页面的编译过程。有什么建议?

I'm looking for detailed technical information on the compilation process for aspx pages and vs2008. Recently I have been learning about controlbuilders and pageparserfilters. I have downloaded some code to clean out extra white spaces in my html in order to make the pages smaller. The code works great, but I don't understand WHY it works. I need to learn more about the page compilation process. Any suggestions?

推荐答案

`

Compilation of ASP .Net Pages:`


这是一个众所周知的事实,ASP的.Net网页功能逻辑可以以两种方式被写入。在ASP.NET的code既可以写在ASPX页面内或者它可以作为一个asp_net_ code.cs或VB .NET文件。


It is a well known fact that ASP .Net pages functional logic can be written in two ways. The ASP .Net code can either be written inside the ASPX page or it can be included as a asp_net_code.cs or vb .net file.

在ASPX页面中嵌入了C#或VB的.Net的code时,ASP.NET的运行时自动编译code到一个程序并加载它。如果code被保持在一个单独的源文件或者作为VB或C#文件,它已经由程序员,这将是由运行时间用于进一步执行用于进行编译。

When the ASPX page is embedded with the code of either C# or VB .Net, the ASP .Net run time automatically compiles the code into an assembly and loads it. If the code is kept in a separate source file either as a VB or C# file, it has to be compiled by the programmer, which will be used by the run time for further execution.

Compilation of Script Inside the aspx pages:


当与在.aspx页面本身内的标记创建一个页面时,code可以在两个位置写入。这既可以在页面内放置...标签内或任何地方的&lt之内;%...%>服务器code块。当code为放置在脚本标签中,它被处理成类级别code和发现被认为是呈现所述网页的方法的一部分的任何其他code


When a page is created with the tags inside the .aspx page itself, the code can be written at two locations. It can either be placed inside the ... tag or any where inside the page within the <%.. %> server code blocks. When the code is placed inside the script tag, it is treated to be class level code and any other code found is considered to be a part of the method that renders the web page.

在该ASPNET_WP.EXE得到的是没有隐藏类文件中的code写的aspx页面的请求时,它会动态生成一个类文件的相应页面某处地方,它临时的ASP.NET文件内在.NET安装路径的树结构。然后这个编译成一个DLL,最终成功删除编译后的类文件。它将使从相同的二进制DLL中的页为任何后续请求。如果发现在.aspx文件的时间戳的任何改变,它认识到有一些变化,并再次重新编译它用于进一步使用。

When a the aspnet_wp.exe gets a request for an aspx page which is written without a code behind class file, it generates a class file dynamically for the corresponding page and places it inside the Temporary ASP .Net Files somewhere under the tree structure of the .Net installation path. Then it compiles this into a DLL and finally deletes the class file after successful compilation. It will render the pages from the same binary DLL for any subsequent requests. If it sees any change in the time stamp of the .aspx file, it recognizes that there is some change and recompiles it again for further use.

所以,最后的编译只有一次,所有的后续请求使用编译code / DLL只受理。

So ultimately the compilation is only once and all the subsequent requests are entertained only by using the compiled code/DLL.

Writing ASP .Net Apps with Code behind files:


这些code文件背后的编制通常是手动或做任何使用CSC.EXE命令行编译器通过使用Microsoft Visual Studio .NET中,产生一个输出作为库的扩展构建功能.DLL。现在ASPNET_WP.EXE的工作是非常简单的。它可以直接执行编译code和HTML页面返回到Web服务器。


The compilation of these Code Behind files is usually done manually either using the csc.exe command line compiler or by using the Build feature in Microsoft Visual Studio .Net, which produces an output as a library with an extension of .DLL. Now the job of aspnet_wp.exe is very simple. It can directly execute the compiled code and return the HTML page to the web server.

Execution Flow of ASPX Pages by IIS:


ASP页面的.Net的执行不是由Internet Information Server或短手形IIS单独处理。它是由工作进程ASPNET_WP.EXE照顾。每当IIS接收从Web浏览器或客户端请求一个页面的请求,将其委托的工作,Aspnet_wp.exe进程,这需要后续工作的关心和最后返回的HTML页面返回给IIS。


The execution of ASP .Net pages are not singly handled by the Internet Information Server or in short hand form IIS. It is taken care by the worker process aspnet_wp.exe. Whenever the IIS receives a request from a web browser or a client requesting for a page, it delegates the job to the aspnet_wp.exe process, which takes care of the subsequent jobs and finally returns the HTML page back to the IIS.

在安装ASP .Net和安装过程中创建一个用于ASPNET_ISAPI.DLL文件.aspx文件的关联。当IIS接收来自客户端或Web浏览器的一个aspx页面的请求时,IIS Web服务器移交给ASPNET_ISAPI.DLL,这反过来又实例化ASPNET_WP.EXE工作这一请求。这ASPNET_WP.EXE定型任何未完成的工作就像运行时编译等,按照上面的说明,然后执行一个新的应用领域的ASP .NET应用程序。最后产生的输出页并返回到网络服务器,其中在转把该文件发送到客户端。

When ASP .Net is installed, installation process creates an association for .aspx files with the aspnet_isapi.dll files. When the IIS receives a request from the clients or web browsers for an aspx page, the IIS web server hands this request over to the aspnet_isapi.dll, which in turn instantiates the aspnet_wp.exe job. This aspnet_wp.exe finalizes any unfinished jobs like run time compilation etc., as explained above and then executes the asp .net application in a new application domain. Finally the output page is generated and returned back to the web server, which in-turn sends the file over to the client.

Conclusion:


以上是执行延伸到两背后的code和Embedded aspx页面内code支持的应用程序的一个非常强大的模型。最终写code在任何​​地方是它背后的文件或aspx页面内code里面总是会更快,不会有这两种方法之间的性能差异。


The above is a very robust model of executing an application extending support to both the code behind and code embedded inside aspx pages. Ultimately writing the code in any place be it inside the code behind files or inside the aspx page will always be faster and will not have any performance difference between the two approaches.

可是我在写code单独的类文件中,使与UI从逻辑分离干净的编码方式。

But writing the code inside a separate class file makes a clean coding approach with a separation of UI from the logic.

这篇关于asp.net页面编译过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆