最簡單的方法是使用自定義可見性提供程序在用戶通過身份驗證時隱藏節點。 MVC音樂商店演示有這個an example。
/// <summary>
/// Only displays nodes when a user is not authenticated.
/// </summary>
public class NonAuthenticatedVisibilityProvider
: SiteMapNodeVisibilityProviderBase
{
#region ISiteMapNodeVisibilityProvider Members
/// <summary>
/// Determines whether the node is visible.
/// </summary>
/// <param name="node">The node.</param>
/// <param name="sourceMetadata">The source metadata.</param>
/// <returns>
/// <c>true</c> if the specified node is visible; otherwise, <c>false</c>.
/// </returns>
public override bool IsVisible(ISiteMapNode node, IDictionary<string, object> sourceMetadata)
{
return !HttpContext.Current.Request.IsAuthenticated;
}
#endregion
}
您可以通過指定要使用的節點的visibilityProvider屬性/屬性組裝式調用它。
<mvcSiteMapNode title="$resources:SiteMapLocalizations,LogOnTitle" action="LogOn" visibilityProvider="MvcMusicStore.Code.NonAuthenticatedVisibilityProvider, Mvc Music Store" />