Wednesday, September 9, 2015

MVC Custom Authetication


  public class HomeController : Controller
    {
        [CustomRole]
        public ActionResult Index()
        {
            return View();
        }

  
    }



 [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, Inherited = true, AllowMultiple = true)]
    public class CustomRole : AuthorizeAttribute
    {
        protected override bool AuthorizeCore(HttpContextBase context)
        {
            //Call from db
            var a = 3;
            if (a==2)
            {
                return true;
            }
            else { return false; }
        }
    }

No comments:

Post a Comment