Question

Another hopefully rather trivial mvcSiteMap problem:

I have a few nodes that I only want to show if the user is not authorized, such as the login link. Do I really have to write my own visibility provider?

Alternatively, is there a filter attribute for an asp.net mvc action that expresses "not authorized"?

Cheers, Duffy

Was it helpful?

Solution

Creating a GuestOnly attribute is probably what you want. This works for me:

using System.Web.Mvc;
using System.Web;

namespace Wingspan.Web.Mvc.Attributes
{
    public class GuestOnlyAttribute : AuthorizeAttribute
    {    
        protected override bool AuthorizeCore(HttpContextBase httpContext)
        {
            return !base.AuthorizeCore(httpContext);
        }
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top