Tech Learner
Tech Learner

Reputation: 1317

Authorization for a controller in MVC 3 based on Session value

I am storing Boolean value in session if a user is Admin or not after some business logic. This logic implemented in home page itself. Now I need to authorize admin controller based on this session value. Any suggestion or reference link please.

Session["Admin"] = true;

Upvotes: 0

Views: 399

Answers (1)

Abdoulie Kassama
Abdoulie Kassama

Reputation: 792

You can do something like this in the controller:

 Session["Admin"] = true;
 if (!(bool)Session["Admin"])
 {
    //Do the appropriate action here like redirect 
    return RedirectToAction("NoRights");
 }

Upvotes: 1

Related Questions