温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:LiveBlog v1.0测试版源码
当前文件:
LiveBlog/LiveBlog.Web/Admin/Menu.ascx.cs,打开代码结构图
LiveBlog/LiveBlog.Web/Admin/Menu.ascx.cs,打开代码结构图1using System; 2
using System.IO; 3
using System.Web; 4
using System.Web.UI.WebControls; 5
using System.Web.UI.HtmlControls; 6
using LiveBlog.Core.Providers; 7
using LiveBlog.Core; 8
9
public partial class admin_Menu : System.Web.UI.UserControl 10
{ 11
protected void Page_Load(object sender, EventArgs e) 12
{ 13
if (!Page.IsCallback) 14
BindMenu(); 15
} 16
17
private void BindMenu() 18
{ 19
foreach (SiteMapNode adminNode in SiteMap.Providers["SecuritySiteMap"].RootNode.ChildNodes) 20
{ 21
if (adminNode.IsAccessibleToUser(HttpContext.Current)) 22
{ 23
if (!Request.RawUrl.ToUpperInvariant().Contains("/ADMIN/") && (adminNode.Url.Contains("xmanager") || adminNode.Url.Contains("PingServices"))) 24
continue; 25
26
HtmlAnchor a = new HtmlAnchor(); 27
a.HRef = adminNode.Url; 28
29
a.InnerHtml = "<span>" + Translate(adminNode.Title) + "</span>";//"<span>" + Translate(info.Name.Replace(".aspx", string.Empty)) + "</span>"; 30
if (Request.RawUrl.EndsWith(adminNode.Url, StringComparison.OrdinalIgnoreCase)) 31
a.Attributes["class"] = "current"; 32
HtmlGenericControl li = new HtmlGenericControl("li"); 33
li.Controls.Add(a); 34
ulMenu.Controls.Add(li); 35
} 36
} 37
38
if (!Request.RawUrl.ToUpperInvariant().Contains("/ADMIN/")) 39
AddItem(Resources.labels.changePassword, Utils.RelativeWebRoot + "login.aspx"); 40
} 41
42
public void AddItem(string text, string url) 43
{ 44
HtmlAnchor a = new HtmlAnchor(); 45
a.InnerHtml = "<span>" + text + "</span>"; 46
a.HRef = url; 47
48
HtmlGenericControl li = new HtmlGenericControl("li"); 49
li.Controls.Add(a); 50
ulMenu.Controls.Add(li); 51
} 52
53
public string Translate(string text) 54
{ 55
try 56
{ 57
return this.GetGlobalResourceObject("labels", text).ToString(); 58
} 59
catch (NullReferenceException) 60
{ 61
return text; 62
} 63
} 64
65
} 66





}
}