Today, I was owndering if I could use the [Authorize] attribute with regions in C#
I never found a satisfying answer, but I think I found an answer
[Authorize(Roles = "Admin")]
#region testRegion
// GET: /Home/Index
public virtual ActionResult Index()
{
return View();
}
#endregion
With this code, only users with the "Admin" role can see this page
No, you can't.
Regions are only for human readability and the're ignored by the compiler.
In your example, the attribute is being applied to the Index() method