ScrewTurn Wiki发现之路(1)--masterpage.master

materpage.master是大部分页面的masterpage,我选择从这里开始。

关键服务器控件







masterpage.master有这几个服务器控件。 而masterpage.master.cs里
protected void Page_Load(object sender, EventArgs e) {
 if(Settings.PrivateAccess && SessionFacade.LoginKey == null && !Path.GetFileName(Request.PhysicalPath).ToLowerInvariant().Equals("login.aspx") && !Path.GetFileName(Request.PhysicalPath).ToLowerInvariant().Equals("register.aspx")) {
  Response.Redirect("Login.aspx");
 }
 PrintHtmlHead();
 PrintHeader();
 PrintSidebar();
 PrintFooter();
 PrintPageHeaderAndFooter();
}
非常直白,几乎不需要注释。

缓存html片段

服务器控件作为缓存html片段的插入点
Content.PseudoCache.TryGetValue("PageHeader", out h)
Content.PseudoCache["PageHeader"] = h;
类似的语句在sw里大量出现,可以算是一种模式了。

TryGetValue

string s;
if(!Content.PseudoCache.TryGetValue("Sidebar", out s)) {
 s = FormattingPipeline.FormatWithPhase1And2(Tools.LoadFile(Settings.SidebarFile), null);
 Content.PseudoCache["Sidebar"] = s;
}
lblSidebarDiv.Text = FormattingPipeline.FormatWithPhase3(s, null);
Content.PseudoCache.TryGetValue类似于int.TryParse PrintHtmlHead和PrintSidebar值得关注一下.

3rd party plugins

public void PrintHtmlHead() {
 string h;
 if(!Content.PseudoCache.TryGetValue("Head", out h)) {
  StringBuilder sb = new StringBuilder();
  sb.Append(@"");
  sb.Append("\n");
  sb.Append(@"");
  sb.Append("\n");
  sb.Append(Tools.Includes);
  h = sb.ToString();
  Content.PseudoCache["Head"] = h;
 }
 // Use a Control to allow 3rd party plugins to programmatically access the Page header
 Literal c = new Literal();
 c.Text = h;
 Page.Header.Controls.Add(c);
}
在注释处插入3rd party plugins

可配置的sidebar

public void PrintSidebar() {
 string s;
 if(!Content.PseudoCache.TryGetValue("Sidebar", out s)) {
  s = FormattingPipeline.FormatWithPhase1And2(Tools.LoadFile(Settings.SidebarFile), null);
  Content.PseudoCache["Sidebar"] = s;
 }
 lblSidebarDiv.Text = FormattingPipeline.FormatWithPhase3(s, null);
}
Tools.LoadFile(Settings.SidebarFile)
->
public static string SidebarFile {
 get { return PublicDirectory + "Sidebar.cs"; }
}
通过一个Sidebar.cs来配置sidebar sidebar.cs的内容
RSS
====Navigation==== * '''[MainPage|Main Page]''' * [RandPage.aspx|Random Page] * [Edit.aspx|Create a new Page] * [AllPages.aspx|All Pages] * [Category.aspx|Categories] * [Admin.aspx|Administration] * [Upload.aspx|File Management] * [Login.aspx|Login/Logout] * [Language.aspx|Language Selection] * [Profile.aspx|Your Profile] * [Register.aspx|Create Account] '''Quick Search'''{BR} {SEARCHBOX}{BR} [Search.aspx?FullText=1|Advanced Search »] [image|PoweredBy|Images/PoweredBy.png|http://www.screwturn.eu]
而FormattingPipeline.FormatWithPhase3会负责把这些wiki标签转换成html FormattingPipeline总共有三个方法,都是作把wiki标签转换成html的。
public static string FormatWithPhase1And2(string raw, PageInfo current)
public static string FormatWithPhase1And2(string raw, PageInfo current, out PageInfo[] linkedPages)
public static string FormatWithPhase3(string raw, PageInfo current)
这是转换成的html

这个sidebar是相对静态的,不会因为用户的登陆状态或者不通的权限的用户有所改变。至少在masterpage里没有。 而在相对静态的html里也用wiki标签,感觉上是多此一举的。也许以后可以看出有其他用意。或许某个地方,允许用户使用wiki标签编辑sidebar。
Tag标签: ScrewTurn Wiki
posted @ 2008-03-27 16:09 nfa2dfa 阅读(187) 评论(0)  编辑 收藏 所属分类: Asp.net

标题  
姓名  
主页
Email (只有博主才能看到) 
验证码 *  看不清,换一张 [登录][注册]
内容(请不要发表任何与政治相关的内容)  
  登录  使用高级评论  新用户注册  返回页首  恢复上次提交      
该文被作者在 2008-03-28 15:15 编辑过


相关链接: