它最终以一种或另一种方式在已发布的 bin 文件夹中生成的 .dll
.aspx 和 .ascx 文件生成控制对象树,其中 %>aaa<% 之间的所有字符串都被转换为 Literal("aaa") 并插入到正确位置的控制树中。
这些来自 Page(或您选择的基本 Page 类)和 WebUserControl 的类总是被编译但没有预编译它们驻留在临时 asp.net 文件夹中;通过预编译,它们会立即放入您的预编译包中。
例如下面的 .ascx
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="WebUserControl.ascx.cs" Inherits="WebUserControl" %>
<div class="customhtml">
<asp:Label ID="Label1" runat="server" Text="<%#Page.Title %>"></asp:Label>
<asp:Button ID="Button1" runat="server" Text="Button" />
</div>
结果如下(选项没有合并): webusercontrol.ascx.#hash#.compiled
<?xml version="1.0" encoding="utf-8"?>
<preserve resultType="3" virtualPath="/WebSite1/WebUserControl.ascx" hash="fffffff7f6e43006" filehash="8f74adc78f7714d1" flags="110000" assembly="App_Web_aslslubn" type="ASP.webusercontrol_ascx">
<filedeps>
<filedep name="/WebSite1/WebUserControl.ascx" />
<filedep name="/WebSite1/WebUserControl.ascx.cs" />
</filedeps>
</preserve>
这使您可以找到它编译成的程序集 - App_Web_#hash# 和类型 - ASP.webusercontrol_ascx
反汇编它会显示以下类声明:
using System;
using System.Diagnostics;
using System.Globalization;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace ASP
{
public class webusercontrol_ascx : WebUserControl
{
private static bool __initialized;
[DebuggerNonUserCode]
public webusercontrol_ascx()
{
this.AppRelativeVirtualPath = "~/WebUserControl.ascx";
if (webusercontrol_ascx.__initialized)
return;
webusercontrol_ascx.__initialized = true;
}
[DebuggerNonUserCode]
private Label __BuildControlLabel1()
{
Label label = new Label();
this.Label1 = label;
label.ApplyStyleSheetSkin(this.Page);
label.ID = "Label1";
label.DataBinding += new EventHandler(this.__DataBindingLabel1);
return label;
}
public void __DataBindingLabel1(object sender, EventArgs e)
{
Label label = (Label) sender;
Control bindingContainer = label.BindingContainer;
label.Text = Convert.ToString(this.Page.Title, (IFormatProvider) CultureInfo.CurrentCulture);
}
[DebuggerNonUserCode]
private Button __BuildControlButton1()
{
Button button = new Button();
this.Button1 = button;
button.ApplyStyleSheetSkin(this.Page);
button.ID = "Button1";
button.Text = "Button";
return button;
}
[DebuggerNonUserCode]
private void __BuildControlTree(webusercontrol_ascx __ctrl)
{
IParserAccessor parserAccessor = (IParserAccessor) __ctrl;
parserAccessor.AddParsedSubObject((object) new LiteralControl("\r\n<div class=\"customhtml\">\r\n "));
Label label = this.__BuildControlLabel1();
parserAccessor.AddParsedSubObject((object) label);
parserAccessor.AddParsedSubObject((object) new LiteralControl("\r\n "));
Button button = this.__BuildControlButton1();
parserAccessor.AddParsedSubObject((object) button);
parserAccessor.AddParsedSubObject((object) new LiteralControl("\r\n</div>\r\n"));
}
[DebuggerNonUserCode]
protected override void FrameworkInitialize()
{
base.FrameworkInitialize();
this.__BuildControlTree(this);
}
}
}
特别是,您可以在添加 LiteralControl 时找到您的 HTML 代码
[DebuggerNonUserCode]
private void __BuildControlTree(webusercontrol_ascx __ctrl)
{
IParserAccessor parserAccessor = (IParserAccessor) __ctrl;
parserAccessor.AddParsedSubObject((object) new LiteralControl("\r\n<div class=\"customhtml\">\r\n "));
Label label = this.__BuildControlLabel1();
parserAccessor.AddParsedSubObject((object) label);
parserAccessor.AddParsedSubObject((object) new LiteralControl("\r\n "));
Button button = this.__BuildControlButton1();
parserAccessor.AddParsedSubObject((object) button);
parserAccessor.AddParsedSubObject((object) new LiteralControl("\r\n</div>\r\n"));
}