TGViewer
Programming & AI Tips 💡 Programming & AI Tips 💡 @programmingtip · 46.3K subscribers
Post #425 8.49K
Favor Privileges over Role Checks ⛔️

A very common practice in web applications, especially those written using the ASP.NET built-in Role provider, is to perform role checks throughout the code to determine whether a user should have access to a particular page or control or command. 🔍

For instance, you might see something like this ♻️ :

if (User.IsInRole(Roles.Administrators))
{
SomeSpecialControl.Visible = true;
}


The problems with the maintainability of this approach become apparent after a short while.❗️

For one, any buttons or other controls on the SomeSpecialControl above that post back to the page should also do a role check to ensure the user submitting the postback is in an acceptable role, otherwise a security hole may be present and users outside of these roles may be able to perform privileged actions. ☠️

🔸🔹🔸🔹

Introducing Privileges ✅

Wouldn't it be better to act like this❓

EditorPanel.Visibility = CurrentUser.CanEdit(CurrentArticle);


This is very clear and is at the appropriate level of abstraction. 💎

CanEdit isn’t itself a privilege; we can look at it as a sort of helper method in this case that lets us write clear and concise code. ✨


https://t.me/pgimg/127

[ Full Article ] : bit.do/prauth

〰〰〰〰〰〰
#AspMvc #Authorization
@ProgrammingTip
Telegram Programming Tips Resources
More from @programmingtip
  1. Oct 5, 2026AI is changing the developer career ladder 🚀 GitHub's latest developer career advice is r…
  2. Oct 2, 2026GPT-6 Astra gets an Ultrafast API tier 🚀 OpenAI added an Ultrafast speed tier for GPT-6 A…
  3. Oct 1, 2026Cloudflare shipped an agentic CLI for its API ⚡️ Cloudflare launched cf, an agentic CLI fo…
  4. Sep 30, 2026OpenAI introduced Dots, always-on agents 🚀 OpenAI introduced Dots, its take on always-on…
  5. Sep 29, 2026Claude Sonnet 5.5 is built for coding agents 🚀 Anthropic released Claude Sonnet 5.5 for t…
  6. Sep 26, 2026Claude Opus 5.5 is available in the API 🚀 Anthropic released Claude Opus 5.5, and it is a…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →