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

推荐订阅源

Google Online Security Blog
Google Online Security Blog
博客园_首页
酷 壳 – CoolShell
酷 壳 – CoolShell
Jina AI
Jina AI
博客园 - Franky
大猫的无限游戏
大猫的无限游戏
Hugging Face - Blog
Hugging Face - Blog
博客园 - 司徒正美
V
V2EX
雷峰网
雷峰网
云风的 BLOG
云风的 BLOG
V
Visual Studio Blog
F
Full Disclosure
Y
Y Combinator Blog
V
V2EX - 技术
Attack and Defense Labs
Attack and Defense Labs
S
Security @ Cisco Blogs
Schneier on Security
Schneier on Security
Microsoft Azure Blog
Microsoft Azure Blog
SecWiki News
SecWiki News
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
The GitHub Blog
The GitHub Blog
量子位
PCI Perspectives
PCI Perspectives
S
Secure Thoughts
D
Darknet – Hacking Tools, Hacker News & Cyber Security
AWS News Blog
AWS News Blog
Blog — PlanetScale
Blog — PlanetScale
爱范儿
爱范儿
K
Kaspersky official blog
B
Blog
A
Arctic Wolf
Hacker News: Ask HN
Hacker News: Ask HN
L
LangChain Blog
T
Tor Project blog
P
Privacy & Cybersecurity Law Blog
Recent Announcements
Recent Announcements
宝玉的分享
宝玉的分享
The Register - Security
The Register - Security
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
L
Lohrmann on Cybersecurity
D
Docker
A
About on SuperTechFans
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Google DeepMind News
Google DeepMind News
The Last Watchdog
The Last Watchdog
S
Security Affairs
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
P
Privacy International News Feed
Simon Willison's Weblog
Simon Willison's Weblog

博客园 - 小罗

学习CRYPTO C#中使用网络函数 (第一部分 用户函数)[翻译] C#图片处理类 在WINCE或Mobile下面获取当前目录 (翻译)从底层了解ASP.NET体系结构 采用HttpModules来重写URLs 使用会话状态(一) 小技巧:ASP.NET中编程杀死进程 - 小罗 - 博客园 ASP.NET—From验证:全部代码及讲解 ASP.NET如何存取 SQLServer数据库图片 ASP.NET基本编程习惯 用asp.net还原与恢复sqlserver数据库 ASP.NET 2.0移动开发之定义设备筛选器 Session丢失原因与解决方案小结 小心!目录删除及重命名操作,一定丢失Session~~ C# 文件操作(上传 下载 删除 文件列表...) 40 种网页技巧 过滤ASP.NET输出HTML中的无用空格 在ASP.NET中创建安全的web站点(配置)
ASP.NET Forums 页面模型分析
小罗 · 2008-01-19 · via 博客园 - 小罗

 

ASP.NET 提供两个用于管理可视元素和代码的模型,即单文件页模型和代码隐藏页模型。具体内容可以参考MSDN(ms-help://MS.MSDNQTR.v80.chs/MS.MSDN.v80/MS.VisualStudio.v80.chs/dv_aspnetcon/html/81b13e7a-b95b-4285-906f-d2dd77411417.htm)。
在ASP.NET Forums的页面中使用了代码隐藏页模型,但是与典型的代码隐藏页模型又稍有区别。
Default.aspx的内容如下: 

<%@ Page Language="C#" %>
<%@ Import Namespace="AspNetForums.Components" %>
<%@ Register TagPrefix="Forums" Namespace="AspNetForums.Controls" Assembly="AspNetForums.Controls" %>
<%@ Register TagPrefix="mp" Namespace="MetaBuilders.WebControls.MasterPages" Assembly="MetaBuilders.WebControls.MasterPages" %>
<mp:ContentContainer runat="server" id="MPContainer" MasterPageFile="~/Themes/MasterPage.ascx">
    <mp:Content id="HeadTag" runat="server">
    <meta http-equiv="Refresh" content="300" />
    </mp:Content>
    <mp:Content id="MainContent" runat="server">
        <Forums:ForumGroupView runat="server" />
    </mp:Content>    
</mp:ContentContainer>
 首先让我们先熟悉一下Asp.Net的指令语法:指定当页和用户控件编译器处理 ASP.NET Web 窗体页 (.aspx) 和用户控件 (.ascx) 文件时所使用的设置。
ASP.NET 页框架支持以下指令:
@ Page 定义 ASP.NET 页分析器和编译器使用的特定于页的属性。只能包含在 .aspx 文件中。
@ Control 定义 ASP.NET 页分析器和编译器使用的控件特定属性。只能包含在 .ascx 文件(用户控件)中。
@ Import 将命名空间显式导入页或用户控件中。
@ Register 将别名与命名空间及类名关联起来,从而允许用户控件和自定义服务器控件在被包括到请求的页或用户控件时呈现。
@ Assembly 在编译过程中将程序集链接到当前页,以使程序集的所有类和接口都可用在该页上。

根据指令语法语法我们解读一下default.aspx:
 

<%@ Page Language="C#" %>   
http://www.knowsky.com指定在对页中的所有内联呈现(<% %> 和 <%= %>)和代码声明块进行编译时使用的语言为C#
<%@ Import Namespace="AspNetForums.Components" %>
将命名空间显式导入到 ASP.NET网页中,同时使导入的命名空间的所有类和接口可用于文件。
<%@ Register TagPrefix="Forums" Namespace="AspNetForums.Controls" Assembly="AspNetForums.Controls" %>
创建标记前缀Forums,与程序集AspNetForums.Controls中的命名空间AspNetForums.Controls相关联。
<%@ Register TagPrefix="mp" Namespace="MetaBuilders.WebControls.MasterPages" Assembly="MetaBuilders.WebControls.MasterPages" %> (略)
继续往下看页面部分,其中主要是MetaBuilders的Master Pages 控件的用法,具体用法可参考venjiang大哥的文章(了解Master Pages库),类似Asp.Net 2.0中的MasterPage

 <mp:ContentContainer runat="server" id="MPContainer" MasterPageFile="~/Themes/MasterPage.ascx">
    <mp:Content id="HeadTag" runat="server">
    <meta http-equiv="Refresh" content="300" />
    </mp:Content>
    <mp:Content id="MainContent" runat="server">
        <Forums:ForumGroupView runat="server" />
    </mp:Content>    
</mp:ContentContainer>
其中mp:ContentContainer中的MasterPageFile指定了"母版页"的位置,mp:Content通过id与"母版页"中的mp:region相对应,最终的效果是在加载Default.aspx的时候先加载母版页,然后Default.aspx中的mp:Content添加到母版页中对应的mp:region位置,形成最终的效果。
<meta http-equiv="Refresh" content="300" />页面每300秒刷新一次
<Forums:ForumGroupView runat="server" />
表示在此位置上是Forums:ForumGroupView控件,根据页面指令我们得知对应的控件为AspNetForums.Controls.ForumGroupView,

namespace AspNetForums.Controls

{

    /**//// <summary>

    /// 论坛组列表服务器控件

    /// </summary>

    public class ForumGroupView : SkinnedForumWebControl

    {

}

}

ForumGroupView继承自SkinnedForumWebControl,并实现抽象方法InitializeSkin,实现了代码分离和换皮肤。继续向下查看ForumGroupView的皮肤文件名View-ForumGroupView.ascx:

<!--广告-->

<Forums:Ads Zone="GoogleAdsense" runat="server" />

<!-- 用户登录消息及注册 -->

<%    if ( Users.GetUser().IsAnonymous ) { %>

<table width="100%" cellspacing="0" cellpadding="5" border="0">

    <tr>

        <td>

            <!-- ForumGroupView.Header.End -->

            <Forums:Login SkinFilename="Skin-LoginSmall.ascx" runat="server" ID="Login1" />

            <!-- ForumGroupView.MainCentent.Start -->

        </td>

    </tr>

</table>

<%    }    %>

……

然后下一个嵌套的过程又开始了。
写此篇文章,大量参考了venjiang,宝玉,ugoer等诸位大哥的文章,在次对他们表示中心的感谢,首次发文章,文笔粗糙,狗尾续貂还请各位不吝指教。