惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园 - 【当耐特】
阮一峰的网络日志
阮一峰的网络日志
S
Secure Thoughts
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
T
Tenable Blog
T
Tailwind CSS Blog
WordPress大学
WordPress大学
宝玉的分享
宝玉的分享
Webroot Blog
Webroot Blog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
The Cloudflare Blog
T
Threat Research - Cisco Blogs
V
Visual Studio Blog
Jina AI
Jina AI
V
V2EX
I
InfoQ
Latest news
Latest news
P
Proofpoint News Feed
T
Threatpost
Engineering at Meta
Engineering at Meta
P
Proofpoint News Feed
美团技术团队
The Register - Security
The Register - Security
L
LangChain Blog
Apple Machine Learning Research
Apple Machine Learning Research
aimingoo的专栏
aimingoo的专栏
GbyAI
GbyAI
Cloudbric
Cloudbric
Microsoft Azure Blog
Microsoft Azure Blog
C
Cisco Blogs
U
Unit 42
Microsoft Security Blog
Microsoft Security Blog
MyScale Blog
MyScale Blog
V
Vulnerabilities – Threatpost
TaoSecurity Blog
TaoSecurity Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Recent Commits to openclaw:main
Recent Commits to openclaw:main
W
WeLiveSecurity
博客园 - 司徒正美
T
The Exploit Database - CXSecurity.com
小众软件
小众软件
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
量子位
酷 壳 – CoolShell
酷 壳 – CoolShell
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
博客园_首页
N
News and Events Feed by Topic

博客园 - hgtj

谈谈产品和项目 重新开始写博客 组件 访问被拒绝 --“/”应用程序中的服务器错误。IIS重启不行,系统注销也不行 (转).Net 揭密--JIT怎样运行你的代码 第一部分 (普通调用) MS-SQLSERVER数据库SUSPECT状态如何解决 Com Interop入门 可按任意字段排序的分页存储过程(转) 拨开SOA的面纱(一篇对SOA概念讲解的很透彻的文章) 基于角色管理的系统访问控制 MySQL查询优化系列讲座之查询优化器 SQL语句优化技术分析 对ORM的疑问 MonoRail - 生命周期及controller/action/view详解 (转) 了解AOP(转) 思归的“动态控件的状态问题”的分析 接口的终结解释 (转) 关于类型转换方面的备忘 java设计模式之State(转) javascript 实现类似C#中字符串的Trim()方法
Asp.Net 背后原理
hgtj · 2006-03-10 · via 博客园 - hgtj

原文:Behind the scenes of ASPX files
转载地址:http://blog.joycode.com/microhelper/articles/9811.aspx

Asp.net Page文件通常有两个文件,aspx文件定义外观,cs文件((Code behind文件)处理事件,运行时,每一个cs文件会被编译成dll文件。

当page第一次被访问的时候,
1:.net会根据aspx文件生成一个cs文件
2:用csc.exe把这个cs文件编译成dll
3: 运行编译生成的这个dll

上面的过程只有第一次请求页面时才发生,所以第一次访问某个page时会感觉比较慢。
以后.net就用dll来处理对这个页面的请求,如果aspx文件有变化,,net会重新生成dll文件

生成的这个dll文件可以在
C:\$WINDOWSDir$\Microsoft.NET\Framework\v1.1.4322\Temporary ASP.NET Files\$YourWebAppName$\4449be44\81bf2529
(最后面两级目录的名字是随机的)
目录下找到,我们可以看到这个目录下除了cs文件外还有其他类型的文件,其中

*.cs:??根据aspx文件生成的cs文件
*.res ??资源文件
*cmdline ?用来编译*.cs文件的命令行
*.err? ??编译*.cs的错误
*out ??编译时的输出文件
*.dll ??编译生成的文件
*pdb ??编译生成的文件
*.xml??存储aspx文件名和.net生成的用来命名文件的随机数之间的映射关系

我们可以看到Temporary ASP.NET Files\$YourWebAppName$\目录下的文件,除了xml文件之外都是以随机数字作为文件名,所以需要一个page

的实际名字与随机数字之间的映射关系,这个映射存储在xml文件中。
比如


???
???

我们根据这个映射,找到生成的cs文件

从cs文件里,我们可以看到,cs文件中标出了与aspx原文件相对应的行号
比如

aspx文件中第三行为

相应的cs文件中
#line 3 "F:\CRM\TestControl.ascx"
__ctrl = new System.Web.UI.WebControls.TextBox();
.............

另一方面,我们可以注意到每一个根据aspx文件生成的类都继承了aspx文件的code behind类,并且实现了其接口。

比如:???
public class TestControl_ascx : CRM.TestControl
public class WebForm1_aspx : CRM.WebForm1, System.Web.SessionState.IRequiresSessionState

根据aspx文件生成的类先于code behide类被调用,其构造函数会初始化所依赖的文件

public WebForm1_aspx() {
?System.Collections.ArrayList dependencies;
??????????? if ((ASP.WebForm1_aspx.__initialized == false)) {
??????????????? ASP.WebForm1_aspx.__stringResource = System.Web.UI.TemplateControl.ReadStringResource(typeof(ASP.WebForm1

_aspx));
??????????????? dependencies = new System.Collections.ArrayList();
??????????????? dependencies.Add("F:\\CRM\\webform1.aspx");
??????????????? dependencies.Add("F:\\CRM\\bin\\CRM.DLL");
??????????????? dependencies.Add("F:\\CRM\\TestControl.ascx");
??????????????? ASP.WebForm1_aspx.__fileDependencies = dependencies;
??????????????? ASP.WebForm1_aspx.__initialized = true;
??????????? }
??????????? this.Server.ScriptTimeout = 30000000;
??????? }


其构造函数执行后,会执行override的函数FrameworkInitialize,
函数FrameworkInitialize调用__BuildControlTree 来构造所有页面上的控件,

综上所述,请求aspx页面时,有两个类参与
1:code behind class ?– WebForm1.
2:从ASPX生成的类?– adbdef.

执行的顺序为
1:adbdef的构造函数
2:WebForm1的构造函数
3:adbdef类的方法FrameworkInitialize
4:FrameworkInitialize调用__ BuildTree创建各个控件
5:按顺序调用Page和controls的事件处理程序,ASPX中声明的事件先被处理