本文整理汇总了C#中System.Web.SiteMapProvider类的典型用法代码示例。如果您正苦于以下问题:C# SiteMapProvider类的具体用法?C# SiteMapProvider怎么用?C# SiteMapProvider使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SiteMapProvider类属于System.Web命名空间,在下文中一共展示了SiteMapProvider类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SiteMapNode
public SiteMapNode(SiteMapProvider provider, string key, string url, string title, string description,
IList roles, NameValueCollection attributes, NameValueCollection explicitResourceKeys, string implicitResourceKey) {
_provider = provider;
_title = title;
_description = description;
_roles = roles;
_attributes = attributes;
_key = key;
_resourceKeys = explicitResourceKeys;
_resourceKey = implicitResourceKey;
if (url != null) {
_url = url.Trim();
}
_virtualPath = CreateVirtualPathFromUrl(_url);
if (_key == null) {
throw new ArgumentNullException("key");
}
if (_provider == null) {
throw new ArgumentNullException("provider");
}
}
示例2: Initialize
private static void Initialize()
{
if (_providers == null)
{
HttpRuntime.CheckAspNetHostingPermission(AspNetHostingPermissionLevel.Low, "Feature_not_supported_at_this_level");
lock (_lockObject)
{
if (_providers == null)
{
SiteMapSection siteMap = RuntimeConfig.GetAppConfig().SiteMap;
if (siteMap == null)
{
_providers = new SiteMapProviderCollection();
}
else
{
if (!siteMap.Enabled)
{
throw new InvalidOperationException(System.Web.SR.GetString("SiteMap_feature_disabled", new object[] { "system.web/siteMap" }));
}
siteMap.ValidateDefaultProvider();
_providers = siteMap.ProvidersInternal;
_provider = _providers[siteMap.DefaultProvider];
_providers.SetReadOnly();
}
}
}
}
}
示例3: GetCurrentNode
public static SiteMapNode GetCurrentNode(SiteMapProvider selectedSiteMapProvider)
{
// get the node matching the current URL location
var currentNode = selectedSiteMapProvider.CurrentNode;
// if there is no node matching the current URL path,
// remove parts until we get a hit
if (currentNode == null)
{
var url = HttpContext.Current.Request.Url.LocalPath;
while (url.Length > 0)
{
// see if we can find a matching node
currentNode = selectedSiteMapProvider.FindSiteMapNode(url);
// if we get a hit, stop
if (currentNode != null) break;
// if not, remove the last path item
var lastSlashlocation = url.LastIndexOf("/");
if (lastSlashlocation < 0) break; // protects us from malformed URLs
url = url.Remove(lastSlashlocation);
}
}
return currentNode;
}
示例4: IsAccessibleToUser
/// <summary>
/// Determines whether node is accessible to user.
/// </summary>
/// <param name="controllerTypeResolver">The controller type resolver.</param>
/// <param name="provider">The provider.</param>
/// <param name="context">The context.</param>
/// <param name="node">The node.</param>
/// <returns>
/// <c>true</c> if accessible to user; otherwise, <c>false</c>.
/// </returns>
public virtual bool IsAccessibleToUser(IControllerTypeResolver controllerTypeResolver, SiteMapProvider provider, HttpContext context, SiteMapNode node)
{
// Is security trimming enabled?
if (!provider.SecurityTrimmingEnabled)
{
return true;
}
// Use child modules
bool result = true;
foreach (var module in ChildModules)
{
try
{
result &= module.IsAccessibleToUser(controllerTypeResolver, provider, context, node);
}
catch (AclModuleNotSupportedException)
{
result &= true; // Convention throughout the provider: if the IAclModule can not authenticate a user, true is returned.
}
if (result == false)
{
return false;
}
}
// Return
return result;
}
示例5: FileSiteMapNode
public FileSiteMapNode(SiteMapProvider provider, string url)
: base(provider, url)
{
Url = url;
Title = VirtualPathUtility.GetFileName(url);
FileExtension = VirtualPathUtility.GetExtension(url).TrimStart('.');
}
示例6: TridionSiteMapNode
public TridionSiteMapNode(SiteMapProvider provider, string key, string uri, string url, string title, string description, IList roles, NameValueCollection attributes, NameValueCollection explicitResourceKeys, string implicitResourceKey) : base(provider, key, url, title, description, roles, attributes, explicitResourceKeys, implicitResourceKey)
{
if (url.StartsWith("tcm:"))
{
this.Url = this.MakeDummyUrl(url);
}
this.Uri = uri;
}
示例7: Add
public void Add(SiteMapProvider provider)
{
if (provider == null)
{
throw new ArgumentNullException("provider");
}
base.Add(provider);
}
示例8: base
/*public MvcSiteMapNode(SiteMapProvider provider, string key, ISiteMapUrlResolver urlResolver)
: base(provider, key)
{
this.urlResolver = urlResolver;
}*/
public MvcSiteMapNode(SiteMapProvider provider, string key, string url, string title, string description,
IList roles, NameValueCollection attributes, NameValueCollection explicitResourceKeys,
string implicitResourceKey, ISiteMapUrlResolver urlResolver, string controllerName, string actionName)
: base(provider, key, url, title, description, roles, attributes, explicitResourceKeys, implicitResourceKey)
{
this.urlResolver = urlResolver;
Controller = controllerName;
Action = actionName;
}
示例9: GetVirtualNodes
public IEnumerable<SiteMapNode> GetVirtualNodes(SiteMapProvider provider)
{
List<SiteMapNode> list = new List<SiteMapNode>();
var siteMapNode = new SiteMapNode(
provider, Guid.NewGuid().ToString(), string.Empty, DummySiteMapNodeTitle, "description");
list.Add(siteMapNode);
return list;
}
示例10: IsDeniedURLWithProvider
public static bool IsDeniedURLWithProvider(string url, string app, SiteMapProvider smProvider)
{
if (url.ToLower().EndsWith("accessdeny.aspx") || url.ToLower().EndsWith("changepassword.aspx") || url.ToLower().EndsWith("default.aspx") || url.ToLower().EndsWith("profile.aspx")) return false;
//if (UserHelper.Username == "admin" || UserHelper.IsAdmin) return false;
if (UserHelper.IsSysAdmin) return false;
if ((smProvider != null) && (smProvider.CurrentNode == null)) return true;
//foreach (string role in RoleDAO.GetRolesForUser(app, UserHelper.Username))
// if (IsDeniedURL(url, app, role)) return true;
return !PermissionDAO.IsAnyRoleInPath(app, RoleDAO.GetRolesForUser(app, UserHelper.Username), url);
}
示例11: Initialize
///<summary>
///Initializes the provider.
///</summary>
///
///<param name="config">A collection of the name/value pairs representing the provider-specific
/// attributes specified in the configuration for this provider.
/// The <c>providerId</c> attribute may be used to override the name being used for looking up an object definition.
/// </param>
///<param name="name">The friendly name of the provider.</param>
///<exception cref="T:System.ArgumentNullException">The <paramref name="name"/> or <paramref name="config"/> is null.</exception>
///<exception cref="T:System.InvalidOperationException">An attempt is made to call <see cref="M:System.Configuration.Provider.ProviderBase.Initialize(System.String,System.Collections.Specialized.NameValueCollection)"></see> on a provider after the provider has already been initialized.</exception>
///<exception cref="T:System.ArgumentException">The <paramref name="name"/> has a length of zero or providerId attribute is not set.</exception>
public override void Initialize(string name, NameValueCollection config)
{
if (config == null) throw new ArgumentNullException("config");
string providerId = config["providerId"];
if (String.IsNullOrEmpty(providerId))
providerId = name;
config.Remove("providerId");
this.wrappedProvider = (System.Web.SiteMapProvider)WebApplicationContext.GetRootContext().GetObject(providerId);
this.wrappedProvider.Initialize(name,config);
}
示例12: GetCurrentSiteMapNodeForChildAction
/// <summary>
/// Gets the current site map node for child action.
/// </summary>
/// <param name="controller">The controller.</param>
/// <param name="provider">The provider.</param>
/// <returns></returns>
public static SiteMapNode GetCurrentSiteMapNodeForChildAction(this ControllerBase controller, SiteMapProvider provider)
{
// Is DefaultSiteMapProvider in use?
DefaultSiteMapProvider mvcProvider = provider as DefaultSiteMapProvider;
if (mvcProvider != null && controller.ControllerContext.IsChildAction)
{
return mvcProvider.FindSiteMapNode(controller.ControllerContext);
}
else
{
return provider.CurrentNode;
}
}
示例13: AddArray
public void AddArray(SiteMapProvider[] providerArray)
{
if (providerArray == null)
{
throw new ArgumentNullException("providerArray");
}
foreach (SiteMapProvider provider in providerArray)
{
if (this[provider.Name] != null)
{
throw new ArgumentException(System.Web.SR.GetString("SiteMapProvider_Multiple_Providers_With_Identical_Name", new object[] { provider.Name }));
}
this.Add(provider);
}
}
示例14: SiteMapNode
public SiteMapNode (SiteMapProvider provider, string key, string url, string title, string description, IList roles, NameValueCollection attributes, NameValueCollection explicitResourceKeys, string implicitResourceKey)
{
if (provider == null)
throw new ArgumentNullException ("provider");
if (key == null)
throw new ArgumentNullException ("key");
this.provider = provider;
this.key = key;
this.url = url;
this.title = title;
this.description = description;
this.roles = roles;
this.attributes = attributes;
this.resourceKeys = explicitResourceKeys;
this.implicitResourceKey = implicitResourceKey;
}
示例15: IsAccessibleToUser
/// <summary>
/// Determines whether node is accessible to user.
/// </summary>
/// <param name="controllerTypeResolver">The controller type resolver.</param>
/// <param name="provider">The provider.</param>
/// <param name="context">The context.</param>
/// <param name="node">The node.</param>
/// <returns>
/// <c>true</c> if accessible to user; otherwise, <c>false</c>.
/// </returns>
public bool IsAccessibleToUser(IControllerTypeResolver controllerTypeResolver, SiteMapProvider provider, HttpContext context, SiteMapNode node)
{
// Is security trimming enabled?
if (!provider.SecurityTrimmingEnabled)
{
return true;
}
// Is it a regular node?
var mvcNode = node as MvcSiteMapNode;
if (mvcNode == null)
{
if (provider.ParentProvider != null)
{
return provider.ParentProvider.IsAccessibleToUser(context, node);
}
}
// If we have roles assigned, check them against the roles defined in the sitemap
if (node.Roles != null && node.Roles.Count > 0)
{
// if there is an authenticated user and the role allows anyone authenticated ("*"), show it
if ((context.User.Identity.IsAuthenticated) && node.Roles.Contains("*"))
{
return true;
}
// if there is no user, but the role allows unauthenticated users ("?"), show it
if ((!context.User.Identity.IsAuthenticated) && node.Roles.Contains("?"))
{
return true;
}
// if the user is in one of the listed roles, show it
if (node.Roles.OfType<string>().Any(role => context.User.IsInRole(role)))
{
return true;
}
// if we got this far, deny showing
return false;
}
// Everything seems OK...
return true;
}