您目前尚未登陆,请选择【登陆】或【注册
首页->全站代码->MyWebPages51aspx汉化最终版>>App-Code/Providers/CustomXmlSitemapProvider.cs>>源码在线查看
温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:MyWebPages51aspx汉化最终版
普通视图
		            
1//=============================================================================================== 2// 3// (c) Copyright Microsoft Corporation. 4// This source is subject to the Microsoft Permissive License. 5// See http://www.microsoft.com/resources/sharedsource/licensingbasics/sharedsourcelicenses.mspx. 6// All other rights reserved. 7// 8//=============================================================================================== 9 10using System; 11using System.Data; 12using System.Configuration; 13using System.Web; 14using System.Web.Security; 15using System.Web.UI; 16using System.Web.UI.WebControls; 17using System.Web.UI.WebControls.WebParts; 18using System.Web.UI.HtmlControls; 19 20namespace MyWebPagesStarterKit.Providers 21{ 22 /// <summary> 23 /// Specialized XmlSiteMapProvider that implements some special behaviour 24 /// </summary> 25 public class CustomXmlSitemapProvider : XmlSiteMapProvider 26 { 27 /// <summary> 28 /// Special IsAccessibleToUser method (see code to get further explanations) 29 /// </summary> 30 public override bool IsAccessibleToUser(HttpContext context, SiteMapNode node) 31 { 32 //if SecurityTrimming is disabled, ALL nodes are accessible by everyone 33 if (!SecurityTrimmingEnabled) 34 return true; 35 36 //Administrators have permissions on all nodes, so we can always return true 37 if ((context.User != null) && (context.User.Identity.IsAuthenticated) && context.User.IsInRole(RoleNames.Administrators.ToString())) 38 return true; 39 40 //The RootNode must be accessible for everyone 41 if (node.ParentNode == null) //if there is no parent-node, the node must be the root node 42 return true; 43 44 //special behaviour for nodes that have a pageId attribute (content-pages) 45 if (node["pageId"] != null) 46 { 47 //first we create the WebPage for the node 48 WebPage page = new WebPage(node["pageId"]); 49 //now check, if we have a logged in user (in role Users) 50 if ((context.User != null) && context.User.Identity.IsAuthenticated) 51 { 52 //we have a authenticated user, therefore the only thing that counts is, if the page is visible 53 return page.Visible; 54 } 55 else 56 { 57 //anonymous user -> we must check if the page is visible, and if it allows anonymous access 58 return ((page.Visible) && (page.AllowAnonymousAccess)); 59 } 60 } 61 else 62 { 63 //if there is no pageId attribute on the node, it is a administration-node 64 //therefore it must not be shown to non-admin users (admin-users are handled further up) 65 return false; 66 } 67 } 68 69 /// <summary> 70 /// Find a SiteMapNode by a give pageId. This method is used recursive. 71 /// </summary> 72 /// <param name="key">The pageId</param> 73 /// <param name="node">Starting node</param> 74 /// <returns></returns> 75 public SiteMapNode FindSiteMapNodeFromPageId(string key, SiteMapNode node) 76 { 77 //Get all ChildNodes of the starting node 78 foreach (SiteMapNode n in GetChildNodes(node)) 79 { 80 //if tha pageId attribute matches the key, we're done and can return the found node 81 if (n["pageId"] == key) 82 { 83 return n; 84 } 85 //otherwise we try to find the SiteMapNode in the childnodes of the current node 86 else 87 { 88 SiteMapNode candidate = FindSiteMapNodeFromPageId(key, n); 89 if (candidate != null) 90 return candidate; 91 } 92 } 93 //if no node with the given pageId is found, we return null 94 return null; 95 } 96 97 /// <summary> 98 /// Resolve eventhandler to get the SiteMapNode corresponding to the currently displayed page 99 /// </summary> 100 public static SiteMapNode Resolve(object sender, SiteMapResolveEventArgs e) 101 { 102 //check, if a CurrentNode could already be determined by the default XmlSiteMapProvider (base class). 103 //if this is not the case and we have a pg-element in the querystring, we must call the FindSiteMapNodeFromPageId-method to find the CurrentNode by pageId 104 //this eventhandler is registered in global.asax, in the "Application_Start" Event 105 if ((e.Provider.CurrentNode == null) && (e.Context.Request.QueryString["pg"] != null)) 106 { 107 return ((CustomXmlSitemapProvider)e.Provider).FindSiteMapNodeFromPageId(e.Context.Request.QueryString["pg"], SiteMap.RootNode); 108 } 109 else 110 { 111 return e.Provider.CurrentNode; 112 } 113 } 114 } 115} 116
还没有找到您心仪的内容?请用.net源码大搜捕
代码片断 打包下载该项目完整源码:MyWebPages51aspx汉化最终版
51Aspx.com 版权所有 CopyRight © 2000-2008. 京ICP备06046876号