Skip to content

Instantly share code, notes, and snippets.

@rexcfnghk
Last active July 1, 2016 14:51
Show Gist options
  • Select an option

  • Save rexcfnghk/169bf771e51278998544ace938d3907c to your computer and use it in GitHub Desktop.

Select an option

Save rexcfnghk/169bf771e51278998544ace938d3907c to your computer and use it in GitHub Desktop.
public class AdminController : Controller
{
public ActionResult Index()
{
// In real production code you should probably use the AuthorizeAttribute
// instead of authorizing/forbidding the user inside an action method
var user = (UserProfile)ViewBag.User;
if (!user.IsAdmin)
{
return new HttpStatusCodeResult(HttpStatusCode.Forbidden);
}
return View();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment