Code:
/ FX-1434 / FX-1434 / 1.0 / untmp / whidbey / REDBITS / ndp / fx / src / xsp / System / Web / SiteMapProvider.cs / 1 / SiteMapProvider.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- /* * Copyright (c) 2002 Microsoft Corporation */ namespace System.Web { using System; using System.Collections; using System.Collections.Specialized; using System.Configuration.Provider; using System.Web.Security; using System.Web.UI; using System.Web.Util; using System.Security.Permissions; [AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)] [AspNetHostingPermission(SecurityAction.InheritanceDemand, Level=AspNetHostingPermissionLevel.Minimal)] public abstract class SiteMapProvider : ProviderBase { private bool _securityTrimmingEnabled; private bool _enableLocalization; private String _resourceKey; internal const String _securityTrimmingEnabledAttrName = "securityTrimmingEnabled"; private const string _allRoles = "*"; private SiteMapProvider _rootProvider; private SiteMapProvider _parentProvider; private object _resolutionTicket = new object(); internal readonly object _lock = new Object(); public virtual SiteMapNode CurrentNode { get { HttpContext context = HttpContext.Current; SiteMapNode result = null; // First check the SiteMap resolve events. result = ResolveSiteMapNode(context); if (result == null) { result = FindSiteMapNode(context); } return ReturnNodeIfAccessible(result); } } public bool EnableLocalization { get { return _enableLocalization; } set { _enableLocalization = value; } } // Parent provider public virtual SiteMapProvider ParentProvider { get { return _parentProvider; } set { _parentProvider = value; } } public string ResourceKey { get { return _resourceKey; } set { _resourceKey = value; } } public virtual SiteMapProvider RootProvider { get { if (_rootProvider == null) { lock (_lock) { if (_rootProvider == null) { Hashtable providers = new Hashtable(); SiteMapProvider candidate = this; providers.Add(candidate, null); while (candidate.ParentProvider != null) { if (providers.Contains(candidate.ParentProvider)) throw new ProviderException(SR.GetString(SR.SiteMapProvider_Circular_Provider)); candidate = candidate.ParentProvider; providers.Add(candidate, null); } _rootProvider = candidate; } } } return _rootProvider; } } public virtual SiteMapNode RootNode { get { SiteMapNode node = GetRootNodeCore(); return ReturnNodeIfAccessible(node); } } public bool SecurityTrimmingEnabled { get { return _securityTrimmingEnabled; } } public event SiteMapResolveEventHandler SiteMapResolve; ////// protected virtual void AddNode(SiteMapNode node) { AddNode(node, null); } protected internal virtual void AddNode(SiteMapNode node, SiteMapNode parentNode) { throw new NotImplementedException(); } public virtual SiteMapNode FindSiteMapNode(HttpContext context) { if (context == null) { return null; } string rawUrl = context.Request.RawUrl; SiteMapNode result = null; // First check the RawUrl result = FindSiteMapNode(rawUrl); if (result == null) { int queryStringIndex = rawUrl.IndexOf("?", StringComparison.Ordinal); if (queryStringIndex != -1) { // check the RawUrl without querystring result = FindSiteMapNode(rawUrl.Substring(0, queryStringIndex)); } if (result == null) { Page page = context.CurrentHandler as Page; if (page != null) { // Try without server side query strings string qs = page.ClientQueryString; if (qs.Length > 0) { result = FindSiteMapNode(context.Request.Path + "?" + qs); } } if (result == null) { // Check the request path result = FindSiteMapNode(context.Request.Path); } } } return result; } public virtual SiteMapNode FindSiteMapNodeFromKey(string key) { return FindSiteMapNode(key); } public abstract SiteMapNode FindSiteMapNode(string rawUrl); public abstract SiteMapNodeCollection GetChildNodes(SiteMapNode node); public virtual SiteMapNode GetCurrentNodeAndHintAncestorNodes(int upLevel) { if (upLevel < -1) { throw new ArgumentOutOfRangeException("upLevel"); } return CurrentNode; } public virtual SiteMapNode GetCurrentNodeAndHintNeighborhoodNodes(int upLevel, int downLevel) { if (upLevel < -1) { throw new ArgumentOutOfRangeException("upLevel"); } if (downLevel < -1) { throw new ArgumentOutOfRangeException("downLevel"); } return CurrentNode; } public abstract SiteMapNode GetParentNode(SiteMapNode node); public virtual SiteMapNode GetParentNodeRelativeToCurrentNodeAndHintDownFromParent ( int walkupLevels, int relativeDepthFromWalkup) { if (walkupLevels < 0) { throw new ArgumentOutOfRangeException("walkupLevels"); } if (relativeDepthFromWalkup < 0) { throw new ArgumentOutOfRangeException("relativeDepthFromWalkup"); } // First get current nodes and hints about its ancestors. SiteMapNode currentNode = GetCurrentNodeAndHintAncestorNodes(walkupLevels); // Simply return if the currentNode is null. if (currentNode == null) { return null; } // Find the target node by walk up the parent tree. SiteMapNode targetNode = GetParentNodesInternal(currentNode, walkupLevels); if (targetNode == null) { return null; } // Get hints about its lower neighborhood nodes. HintNeighborhoodNodes(targetNode, 0, relativeDepthFromWalkup); return targetNode; } public virtual SiteMapNode GetParentNodeRelativeToNodeAndHintDownFromParent( SiteMapNode node, int walkupLevels, int relativeDepthFromWalkup) { if (walkupLevels < 0) { throw new ArgumentOutOfRangeException("walkupLevels"); } if (relativeDepthFromWalkup < 0) { throw new ArgumentOutOfRangeException("relativeDepthFromWalkup"); } if (node == null) { throw new ArgumentNullException("node"); } // First get hints about ancestor nodes; HintAncestorNodes(node, walkupLevels); // walk up the parent node until the target node is found. SiteMapNode ancestorNode = GetParentNodesInternal(node, walkupLevels); if (ancestorNode == null) { return null; } // Get hints about its neighthood nodes HintNeighborhoodNodes(ancestorNode, 0, relativeDepthFromWalkup); return ancestorNode; } private SiteMapNode GetParentNodesInternal(SiteMapNode node, int walkupLevels) { Debug.Assert(node != null); if (walkupLevels <= 0) { return node; } do { node = node.ParentNode; walkupLevels--; } while (node != null && walkupLevels != 0); return node; } /* * A reference node that must be returned by all sitemap providers, this is * required for the parent provider to keep track of the relations between * two providers. * For example, the parent provider uses this method to keep track of the parent * node of child provider's root node. */ protected internal abstract SiteMapNode GetRootNodeCore(); protected static SiteMapNode GetRootNodeCoreFromProvider(SiteMapProvider provider) { return provider.GetRootNodeCore(); } public virtual void HintAncestorNodes(SiteMapNode node, int upLevel) { if (node == null) { throw new ArgumentNullException("node"); } if (upLevel < -1) { throw new ArgumentOutOfRangeException("upLevel"); } } public virtual void HintNeighborhoodNodes(SiteMapNode node, int upLevel, int downLevel) { if (node == null) { throw new ArgumentNullException("node"); } if (upLevel < -1) { throw new ArgumentOutOfRangeException("upLevel"); } if (downLevel < -1) { throw new ArgumentOutOfRangeException("downLevel"); } } public override void Initialize(string name, NameValueCollection attributes) { if (attributes != null) { if (string.IsNullOrEmpty(attributes["description"])) { attributes.Remove("description"); attributes.Add("description", this.GetType().Name); } ProviderUtil.GetAndRemoveBooleanAttribute(attributes, _securityTrimmingEnabledAttrName, Name, ref _securityTrimmingEnabled); } base.Initialize(name, attributes); } public virtual bool IsAccessibleToUser(HttpContext context, SiteMapNode node) { if (node == null) { throw new ArgumentNullException("node"); } if (context == null) { throw new ArgumentNullException("context"); } if (!SecurityTrimmingEnabled) { return true; } if (node.Roles != null) { foreach (string role in node.Roles) { // Grant access if one of the roles is a "*". if (role == _allRoles || context.User != null && context.User.IsInRole(role)) { return true; } } } VirtualPath virtualPath = node.VirtualPath; if (virtualPath == null || !virtualPath.IsWithinAppRoot) { return false; } return System.Web.UI.Util.IsUserAllowedToPath(context, virtualPath); } protected internal virtual void RemoveNode(SiteMapNode node) { throw new NotImplementedException(); } protected SiteMapNode ResolveSiteMapNode(HttpContext context) { SiteMapResolveEventHandler eventHandler = SiteMapResolve; if (eventHandler == null) return null; if (!context.Items.Contains(_resolutionTicket)) { context.Items.Add(_resolutionTicket, true); try { Delegate[] ds = eventHandler.GetInvocationList(); int len = ds.Length; for (int i = 0; i < len; i++) { SiteMapNode ret = ((SiteMapResolveEventHandler)ds[i])(this, new SiteMapResolveEventArgs(context, this)); if (ret != null) { return ret; } } } finally { context.Items.Remove(_resolutionTicket); } } return null; } internal SiteMapNode ReturnNodeIfAccessible(SiteMapNode node) { if (node != null && node.IsAccessibleToUser(HttpContext.Current)) { return node; } return null; } } }Add single node to provider. ///
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- BatchWriter.cs
- LateBoundBitmapDecoder.cs
- base64Transforms.cs
- Dictionary.cs
- TraceHandlerErrorFormatter.cs
- RichTextBoxContextMenu.cs
- DeferredSelectedIndexReference.cs
- MulticastNotSupportedException.cs
- SqlUserDefinedAggregateAttribute.cs
- EventLogTraceListener.cs
- LowerCaseStringConverter.cs
- ListenerConstants.cs
- DoubleCollectionValueSerializer.cs
- CompatibleComparer.cs
- InstanceDataCollection.cs
- DiscreteKeyFrames.cs
- _NegoState.cs
- Int32AnimationBase.cs
- DefaultExpressionVisitor.cs
- XmlDictionary.cs
- ManipulationDevice.cs
- ConfigurationElementProperty.cs
- DataServiceResponse.cs
- M3DUtil.cs
- Brush.cs
- SmtpLoginAuthenticationModule.cs
- VectorAnimation.cs
- TimerElapsedEvenArgs.cs
- DataGridViewCheckBoxCell.cs
- DocumentPageHost.cs
- Enum.cs
- BoundingRectTracker.cs
- FileInfo.cs
- KeyInterop.cs
- RequestQueue.cs
- CallContext.cs
- StorageTypeMapping.cs
- ByteStorage.cs
- FusionWrap.cs
- TextRange.cs
- ConnectionPointCookie.cs
- UnsafeNativeMethodsMilCoreApi.cs
- MetabaseSettingsIis7.cs
- HtmlContainerControl.cs
- TextRenderer.cs
- ActiveXHelper.cs
- CodePageUtils.cs
- Environment.cs
- SymbolEqualComparer.cs
- File.cs
- RoleManagerSection.cs
- SqlDelegatedTransaction.cs
- EncodingDataItem.cs
- ObjectDataSourceChooseTypePanel.cs
- MetadataItem.cs
- ListControl.cs
- ToolStripGrip.cs
- ColorDialog.cs
- WmlCalendarAdapter.cs
- StyleSelector.cs
- CompiledXpathExpr.cs
- VisualStyleRenderer.cs
- Collection.cs
- SafeCloseHandleCritical.cs
- EmptyEnumerator.cs
- Glyph.cs
- DataRecordInternal.cs
- CaseInsensitiveHashCodeProvider.cs
- QilReplaceVisitor.cs
- SessionStateContainer.cs
- DictionarySectionHandler.cs
- DbConnectionStringCommon.cs
- ConnectionManagementSection.cs
- LocationSectionRecord.cs
- MethodCallTranslator.cs
- BlockExpression.cs
- AnnotationAuthorChangedEventArgs.cs
- PathFigure.cs
- EnumValidator.cs
- MarkerProperties.cs
- _SslStream.cs
- SystemUdpStatistics.cs
- CodeCommentStatement.cs
- Control.cs
- AuthorizationRule.cs
- BackgroundFormatInfo.cs
- SystemIPv4InterfaceProperties.cs
- PlainXmlDeserializer.cs
- SqlUserDefinedTypeAttribute.cs
- GridEntry.cs
- SqlCacheDependency.cs
- InstancePersistenceEvent.cs
- DiscoveryReferences.cs
- PrefixHandle.cs
- CellCreator.cs
- ReadOnlyTernaryTree.cs
- XmlAttribute.cs
- IndentedWriter.cs
- WebServiceEndpoint.cs
- OrderedDictionary.cs