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

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
T
Threatpost
Latest news
Latest news
N
News | PayPal Newsroom
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Help Net Security
Help Net Security
D
Darknet – Hacking Tools, Hacker News & Cyber Security
AI
AI
Simon Willison's Weblog
Simon Willison's Weblog
TaoSecurity Blog
TaoSecurity Blog
The Last Watchdog
The Last Watchdog
L
LINUX DO - 热门话题
Google DeepMind News
Google DeepMind News
T
Threat Research - Cisco Blogs
O
OpenAI News
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
T
The Exploit Database - CXSecurity.com
NISL@THU
NISL@THU
Application and Cybersecurity Blog
Application and Cybersecurity Blog
S
Securelist
小众软件
小众软件
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Martin Fowler
Martin Fowler
S
SegmentFault 最新的问题
Cisco Talos Blog
Cisco Talos Blog
云风的 BLOG
云风的 BLOG
AWS News Blog
AWS News Blog
GbyAI
GbyAI
N
News and Events Feed by Topic
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
美团技术团队
Engineering at Meta
Engineering at Meta
A
About on SuperTechFans
博客园 - 三生石上(FineUI控件)
S
Schneier on Security
博客园 - 聂微东
V2EX - 技术
V2EX - 技术
T
Troy Hunt's Blog
SecWiki News
SecWiki News
S
Secure Thoughts
B
Blog RSS Feed
Hugging Face - Blog
Hugging Face - Blog
WordPress大学
WordPress大学
腾讯CDC
H
Heimdal Security Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Apple Machine Learning Research
Apple Machine Learning Research
月光博客
月光博客
www.infosecurity-magazine.com
www.infosecurity-magazine.com
P
Privacy International News Feed

博客园 - kenty06

LINQ 查询Select LINQ之DataContext 数据上下文 Dedecms57 分页 dede:pagelist 说明 window service服务安装错误 命名空间基础知识 - kenty06 - 博客园 C#简单类型转换说明 建立全文索引以及使用 Asp.net中防止用户多次登录的方法 VSS使用手册 开启全文索引 extJS初学小问题之js文件编码 - kenty06 - 博客园 希尔排序 VS2008加载包失败的解决方法 VS2005快捷键(转) 关于 odbc OdbcParameter参数问题 - kenty06 在 dotnet环境下使用 文件dsn - kenty06 关于枚举enum的tostring方法不能重写的一种替代方案 aspx页面事件顺序 - kenty06 - 博客园 C#中的default
asp.net 2.0 学习点滴推荐(001) - kenty06
kenty06 · 2009-05-01 · via 博客园 - kenty06

2009-05-01 20:18  kenty06  阅读(417)  评论()    收藏  举报

在asp.net中,整个文件的内容被解析为类定义,然后被编译成一个程序集,服务器短脚本块被直接加入到类定义中,分散的脚本被合并成该类的一个Render方法,该方法被调用时将所有静态和动态内容写入到响应流中,

例如:

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
    const int _itemcount = 10;
    string GetDisplayItem(int n)
    {
        return "Item #" + n.ToString();
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Simple page</title>
</head>
<body>
   <h1>Test Asp.NET 2.0 Page</h1>
   <ul>
   <% for (int i = 0; i < _itemcount; i++)
      { %>
   <li>
   <%=GetDisplayItem(i)%>
   </li>
   <%} %>   
   </ul>
   <% Response.Write("<h2>Total number of items = " + _itemcount.ToString() + "</h2>"); %>
</body>
</html>

该页面生成的类代码为

public class simplepage_aspx : Page, IRequiresSessionState, IHttpHandler
{
    // Fields
    private static object __fileDependencies;
    private static bool __initialized;
    private const int _itemcount = 10;

    // Methods
    [DebuggerNonUserCode]
    public simplepage_aspx()
    {
        base.AppRelativeVirtualPath = "~/SimplePage.aspx";
        if (!__initialized)
        {
            string[] virtualFileDependencies = new string[] { "~/SimplePage.aspx" };
            __fileDependencies = base.GetWrappedFileDependencies(virtualFileDependencies);
            __initialized = true;
        }
    }

    [DebuggerNonUserCode]
    private HtmlHead __BuildControl__control2()
    {
        HtmlHead head = new HtmlHead("head");
        HtmlTitle title = this.__BuildControl__control3();
        IParserAccessor accessor = head;
        accessor.AddParsedSubObject(title);
        return head;
    }

    [DebuggerNonUserCode]
    private HtmlTitle __BuildControl__control3()
    {
        HtmlTitle title = new HtmlTitle();
        IParserAccessor accessor = title;
        accessor.AddParsedSubObject(new LiteralControl("Simple page"));
        return title;
    }

    [DebuggerNonUserCode]
    private void __BuildControlTree(simplepage_aspx __ctrl)
    {
        this.InitializeCulture();
        HtmlHead head = this.__BuildControl__control2();
        IParserAccessor accessor = __ctrl;
        accessor.AddParsedSubObject(head);
        __ctrl.SetRenderMethodDelegate(new RenderMethod(this.__Render__control1));
    }

    private void __Render__control1(HtmlTextWriter __w, Control parameterContainer)
    {
        __w.Write("\r\n\r\n<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd/%22%3E/r/n/r/n");
        __w.Write("\r\n\r\n<html xmlns=\"http://www.w3.org/1999/xhtml/%22%3E/r/n");
        parameterContainer.Controls[0].RenderControl(__w);
        __w.Write("\r\n<body>\r\n   <h1>Test Asp.NET 2.0 Page</h1>\r\n   <ul>\r\n   ");
        for (int i = 0; i < 10; i++)
        {
            __w.Write("\r\n   <li>\r\n   ");
            __w.Write(this.GetDisplayItem(i));
            __w.Write("\r\n   </li>\r\n   ");
        }
        __w.Write("   \r\n   </ul>\r\n   ");
        int num2 = 10;
        base.Response.Write("<h2>Total number of items = " + num2.ToString() + "</h2>");
        __w.Write(base.GetType().Assembly.Location);
        __w.Write("\r\n</body>\r\n</html>\r\n");
    }

    [DebuggerNonUserCode]
    protected override void FrameworkInitialize()
    {
        base.FrameworkInitialize();
        this.__BuildControlTree(this);
        base.AddWrappedFileDependencies(__fileDependencies);
        base.Request.ValidateInput();
    }

    private string GetDisplayItem(int n)
    {
        return ("Item #" + n.ToString());
    }

    [DebuggerNonUserCode]
    public override int GetTypeHashCode()
    {
        return -328547524;
    }

    [DebuggerNonUserCode]
    public override void ProcessRequest(HttpContext context)
    {
        base.ProcessRequest(context);
    }

    // Properties
    protected HttpApplication ApplicationInstance
    {
        get
        {
            return this.Context.ApplicationInstance;
        }
    }

    protected DefaultProfile Profile
    {
        get
        {
            return (DefaultProfile) this.Context.Profile;
        }
    }
}

在页面任何位置增加    <% =GetType().Assembly.Location %> 来查看生成的代码文件位置以及名称