{"id":116819,"date":"2024-05-19T08:26:30","date_gmt":"2024-05-19T06:26:30","guid":{"rendered":"https:\/\/code-maze.com\/?p=116819"},"modified":"2024-05-19T08:26:30","modified_gmt":"2024-05-19T06:26:30","slug":"aspnetcore-view-based-authorization","status":"publish","type":"post","link":"https:\/\/code-maze.com\/aspnetcore-view-based-authorization\/","title":{"rendered":"View-Based Authorization in ASP.NET Core"},"content":{"rendered":"<p>View-based authorization is an authorization strategy that enables us to manage UI elements&#8217; visibility based on the user&#8217;s identity. In this article, we&#8217;ll take a look at how we can achieve view-based authorization in an ASP.NET core application.<\/p>\n<div style=\"padding: 20px; border-left: 5px #dc2323 solid; display: block; margin-bottom: 20px; box-shadow: 1px 1px 5px 0px lightgrey;\">To download the source code for this article, you can visit our <a href=\"https:\/\/github.com\/CodeMazeBlog\/CodeMazeGuides\/tree\/main\/authorization-dotnet\/ViewBasedAuthorization\" target=\"_blank\" rel=\"nofollow noopener\">GitHub repository<\/a>.<\/div>\n<p>Let&#8217;s begin.<\/p>\n<h2><a id=\"auth\"><\/a>What Is Authorization?<\/h2>\n<p>Before we dive deeper into the implementation of view-based authorization, let&#8217;s take a step back and review the concept of authorization.<\/p>\n<p><strong>Authorization refers to the process of determining what actions or resources a user is permitted to access.<\/strong> It is based on their identity and associated permissions. In other words, <strong>it ensures that the users only interact with the parts of an application that they are authorized to use.<\/strong><\/p>\n<p>Often it&#8217;s the process that comes after <a href=\"https:\/\/code-maze.com\/authentication-aspnet-core-identity\/\" target=\"_blank\" rel=\"noopener\">authentication<\/a>. <strong>While authentication verifies who a user claims to be, authorization determines the level of access granted to authenticated users.<\/strong><\/p>\n<h2><a id=\"view-auth\"><\/a>View-Based Authorization<\/h2>\n<p><strong>In view-based authorization, we conditionally display or enable different view parts, such as buttons, links, and form fields, based on the user&#8217;s authorization status.<\/strong><\/p>\n<p>Unlike other forms of authorization such as route-based or <a href=\"https:\/\/code-maze.com\/aspnetcore-resource-based-authorization\/\" target=\"_blank\" rel=\"noopener\">resource-based authorization<\/a>, which focus on controlling access to entire routes or data resources, view-based authorization targets individual components within the user interface.<\/p>\n<p>Here, we often leverage user roles or policies to determine access to UI elements. We can check whether the current user belongs to a specific role and accordingly render UI elements for them. View-based authorization also allows us to move the authorization logic from the backend to the presentation layer. We can apply authorization rules directly on the razor views without cluttering the controller or backend APIs with authorization-related code.<\/p>\n<h2><a id=\"rbac\"><\/a>Role-Based Access Control (RBAC)<\/h2>\n<p>Building upon the concept of view-based authorization, <a href=\"https:\/\/code-maze.com\/identityserver4-authorization\/\" target=\"_blank\" rel=\"noopener\">Role-Based Access Control (RBAC)<\/a> can help us refine the access within ASP.NET Core Razor views.<\/p>\n<p><strong>RBAC is an authorization technique where access decisions are determined by a user&#8217;s role within the system.<\/strong> It allows us to restrict access to specific UI elements based on the roles associated with the current user:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">@if (User.IsInRole(\"Admin\"))\r\n{\r\n    &lt;a class=\"btn btn-danger\" href=\"\/Delete?id=@document.Id\"&gt;Delete&lt;\/a&gt;\r\n}<\/pre>\n<p>Here, we only display the <em>Delete<\/em> link to users who belong to the <em>Admin<\/em> role. Thus, users who do not have administrator access are unable to delete resources.<\/p>\n<h2><a id=\"pbac\"><\/a>Policy-Based Access Control (PBAC)<\/h2>\n<p>Expanding on the concept of view-based authorization and Role-Based Access Control, let&#8217;s explore <a href=\"https:\/\/code-maze.com\/atribute-based-access-control-blazor-webassembly-identityserver4\/\" target=\"_blank\" rel=\"noopener\">Policy-Based Access Control (PBAC)<\/a>.<\/p>\n<p>PBAC is an authorization model where we decide user access based on policies. <strong>A <em>policy<\/em> refers to a set of rules that define whether a user is authorized to access a particular resource or perform a specific action.<\/strong> Policies are dependent on <em>claims, <\/em>which are individual pieces of information about an authenticated user. <strong>When a user requests access to a resource, we evaluate these policy requirements against the role or claims associated with the user.<\/strong><\/p>\n<p>These policies allow for fine-grained control over access to UI components within ASP.NET Core Razor views:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">@if ((await AuthorizationService.AuthorizeAsync(User, \"EditDocument\")).Succeeded)\r\n{\r\n    &lt;a class=\"btn btn-primary\" href=\"\/Edit?id=@document.Id\"&gt;Edit&lt;\/a&gt;\r\n}<\/pre>\n<p>Here, we use the <code>AuthorizeAsync()<\/code> method to check whether the current user is authorized according to the <em>EditDocument<\/em> policy defined in the application&#8217;s policy configuration. If the user is authorized, we display the <em>Edit<\/em> link.<\/p>\n<h2><a id=\"setup\"><\/a>Implement View-Based Authorization in ASP.NET Core<\/h2>\n<p>Let&#8217;s create an application in which, based on a user&#8217;s roles and policies, we&#8217;ll conditionally display UI elements in the view.<\/p>\n<p>Firstly, we use the <code>dotnet new webapp<\/code> command to create a new ASP.NET Core Razor Pages project in which to implement view-based authorization. We&#8217;ll be using the SQLite Entity Framework package to manage database persistence.<\/p>\n<p>Now let&#8217;s create a <code>Document<\/code> class:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">public class Document\r\n{\r\n    public int Id { get; set; }\r\n    public required string Title { get; set; }\r\n    public string Content { get; set; } = string.Empty;\r\n}<\/pre>\n<p>This class will act as the base model for our application.<\/p>\n<p>Next, let&#8217;s create a <a href=\"https:\/\/github.com\/CodeMazeBlog\/CodeMazeGuides\/blob\/main\/authorization-dotnet\/ViewBasedAuthorization\/ViewBasedAuthorization\/Data\/DocumentContext.cs\" target=\"_blank\" rel=\"nofollow noopener\">context class<\/a> named <code>DocumentContext<\/code> that inherits from <code>IdentityDbContext&lt;IdentityUser&gt;<\/code>. This will allow us to extend the capabilities of <code>IdentityDbContext<\/code> to include default user and role management features provided by ASP.NET Core Identity.<\/p>\n<h3><a id=\"identity\"><\/a>Identity Configuration<\/h3>\n<p>Now let&#8217;s set up the default user and role management using <code>DocumentContext<\/code> as the database:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">builder.Services.AddDefaultIdentity&lt;IdentityUser&gt;(options =&gt;\r\n{\r\n    options.SignIn.RequireConfirmedAccount = true;\r\n})\r\n.AddRoles&lt;IdentityRole&gt;()\r\n.AddEntityFrameworkStores&lt;DocumentContext&gt;();<\/pre>\n<p>Here, we configure the default Identity system with <code>IdentityUser<\/code> as the user type. <code>IdentityUser<\/code> is the built-in user model provided by ASP.NET Core Identity, which includes properties like <code>Id<\/code>, <code>UserName<\/code>, and <code>Email<\/code>.<\/p>\n<p>We also extend the Identity system to support role-based authorization. It registers <code>IdentityRole<\/code> as the role type associated with users.<\/p>\n<h3><a id=\"policy\"><\/a>Policy Configuration<\/h3>\n<p>Next, let&#8217;s set up some policies in the application to restrict access to the resources:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">builder.Services.AddAuthorizationBuilder()\r\n    .AddPolicy(\"EditDocument\", policy =&gt; policy.RequireClaim(\"Permission\", \"CanEdit\"))\r\n    .AddPolicy(\"DeleteDocument\", policy =&gt; policy.RequireRole(\"Admin\"));<\/pre>\n<p>The <em>EditDocument\u00a0<\/em>policy requires the users to have a <em>Permission<\/em> claim with the value <em>CanEdit, <\/em>while<em>\u00a0<\/em>the <em>DeleteDocument<\/em> policy requires the user to be an admin.<\/p>\n<p>At this point, we can create and apply initial migrations to generate our <em>Documents<\/em> table and default ASP.NET Identity tables such as <em>AspNetUsers<\/em>\u00a0and <em>AspNetRoles<\/em>.<\/p>\n<h3><a id=\"users\"><\/a>User Creation for View-Based Authorization<\/h3>\n<p>To demonstrate how view-based authorization works for different users, let&#8217;s seed our application with different user roles:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">private static void SeedUser(UserManager&lt;IdentityUser&gt; userManager, string email, string password,\r\n    string roleName, params Claim[] claims)\r\n{\r\n    var user = userManager.FindByEmailAsync(email).Result;\r\n\r\n    if (user is null)\r\n    {\r\n        user = new IdentityUser { UserName = email, Email = email, EmailConfirmed = true };\r\n        userManager.CreateAsync(user, password);\r\n    }\r\n\r\n    if (!userManager.IsInRoleAsync(user, roleName).Result)\r\n    {\r\n        userManager.AddToRoleAsync(user, roleName);\r\n    }\r\n\r\n    foreach (var claim in claims)\r\n    {\r\n        if (!userManager.GetClaimsAsync(user)\r\n            .Result\r\n            .Any(c =&gt; c.Type == claim.Type &amp;&amp; c.Value == claim.Value))\r\n        {\r\n            userManager.AddClaimAsync(user, claim);\r\n        }\r\n    }\r\n}<\/pre>\n<p>Using the <code>SeedUser()<\/code> method, we can create users in the <em>AspNetUsers <\/em>table and assign them specific roles or claims. Let&#8217;s create three different types of users &#8211; <em>admin<\/em>, <em>editor<\/em>, and <em>user<\/em>:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">SeedUser(userManager,\r\n    \"admin@docmanager.com\",\r\n    \"Admin123!\",\r\n    \"Admin\",\r\n    new Claim(\"Permission\", \"CanEdit\"));\r\n\r\nSeedUser(userManager,\r\n    \"editor@docmanager.com\",\r\n    \"Editor123!\",\r\n    \"Editor\",\r\n    new Claim(\"Permission\", \"CanEdit\"));\r\n\r\nSeedUser(userManager, \"user@docmanager.com\", \"User123!\", \"User\");<\/pre>\n<p>The roles &#8220;Admin&#8221;, &#8220;Editor&#8221;, and &#8220;User&#8221; represent different levels of access or privileges within the application. In addition, we give a claim to the &#8220;Editor&#8221; and &#8220;Admin&#8221; users, which asserts that those users can edit documents within the application.<\/p>\n<h2><a id=\"in-action\"><\/a>View-Based Authorization in Action<\/h2>\n<p>Now that we have our tables, users, and their respective roles set up, let&#8217;s see our Document Management application in action.<\/p>\n<p>Let&#8217;s create an Index page that a logged-in user lands on:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"html\">&lt;table class=\"table table-striped\"&gt;\r\n    &lt;thead&gt;\r\n        &lt;tr&gt;\r\n            &lt;th&gt;Title&lt;\/th&gt;\r\n            &lt;th&gt;Actions&lt;\/th&gt;\r\n        &lt;\/tr&gt;\r\n    &lt;\/thead&gt;\r\n    &lt;tbody&gt;\r\n        @foreach (var document in Model.Documents)\r\n        {\r\n            &lt;tr&gt;\r\n                &lt;td&gt;@document.Title&lt;\/td&gt;\r\n                &lt;td&gt;\r\n                    @if ((await AuthorizationService.AuthorizeAsync(User, \"EditDocument\")).Succeeded)\r\n                    {\r\n                        &lt;a class=\"btn btn-primary\" href=\"\/Edit?id=@document.Id\"&gt;Edit&lt;\/a&gt;\r\n                    }\r\n                    @if (User.IsInRole(\"Admin\"))\r\n                    {\r\n                        &lt;a class=\"btn btn-danger\" href=\"\/Delete?id=@document.Id\"&gt;Delete&lt;\/a&gt;\r\n                    }\r\n                &lt;\/td&gt;\r\n            &lt;\/tr&gt;\r\n        }\r\n    &lt;\/tbody&gt;\r\n&lt;\/table&gt;\r\n&lt;hr\/&gt;\r\n&lt;p&gt;&lt;a class=\"btn btn-success\" href=\"\/Add\"&gt;Add New Document&lt;\/a&gt;&lt;\/p&gt;<\/pre>\n<p>We inject the <code>AuthorizationService<\/code> into the view. Using this, we can dynamically perform authorization checks directly within the Razor Page. Finally, authorization policies (<code>\"EditDocument\"<\/code>) and role-based checks (<code>User.IsInRole(\"Admin\")<\/code>) dictate which actions are available to the user.<\/p>\n<h3><a id=\"ui-diff\"><\/a>User Interface Differences<\/h3>\n<p>Let&#8217;s see how the application user interface varies for different types of users.<\/p>\n<p>A &#8220;User&#8221; doesn&#8217;t have the permission to edit or delete documents. Thus, all they see is an option to add new documents:<\/p>\n<p><a href=\"https:\/\/code-maze.com\/wp-content\/uploads\/2024\/05\/msedge_BPIhYjB9Ud.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-116821\" src=\"https:\/\/code-maze.com\/wp-content\/uploads\/2024\/05\/msedge_BPIhYjB9Ud.png\" alt=\"UI for user in view-based authorization\" width=\"835\" height=\"185\" srcset=\"https:\/\/code-maze.com\/wp-content\/uploads\/2024\/05\/msedge_BPIhYjB9Ud.png 835w, https:\/\/code-maze.com\/wp-content\/uploads\/2024\/05\/msedge_BPIhYjB9Ud-300x66.png 300w, https:\/\/code-maze.com\/wp-content\/uploads\/2024\/05\/msedge_BPIhYjB9Ud-768x170.png 768w\" sizes=\"auto, (max-width: 835px) 100vw, 835px\" \/><\/a><\/p>\n<p>An &#8220;Editor&#8221; has permission to edit the existing documents. Thus, in addition to the ability to add new documents, they can also perform &#8220;Edit&#8221; actions:<\/p>\n<p><a href=\"https:\/\/code-maze.com\/wp-content\/uploads\/2024\/05\/msedge_QicJrrJjgr.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-116822 size-full\" src=\"https:\/\/code-maze.com\/wp-content\/uploads\/2024\/05\/msedge_QicJrrJjgr.png\" alt=\"UI for an editor in view-based authorization\" width=\"843\" height=\"199\" srcset=\"https:\/\/code-maze.com\/wp-content\/uploads\/2024\/05\/msedge_QicJrrJjgr.png 843w, https:\/\/code-maze.com\/wp-content\/uploads\/2024\/05\/msedge_QicJrrJjgr-300x71.png 300w, https:\/\/code-maze.com\/wp-content\/uploads\/2024\/05\/msedge_QicJrrJjgr-768x181.png 768w\" sizes=\"auto, (max-width: 843px) 100vw, 843px\" \/><\/a><\/p>\n<p>Finally, an &#8220;Admin&#8221; has all the permissions, so they can add, edit, and delete a document:<\/p>\n<p><a href=\"https:\/\/code-maze.com\/wp-content\/uploads\/2024\/05\/msedge_dS9kJaGb5V.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-116823\" src=\"https:\/\/code-maze.com\/wp-content\/uploads\/2024\/05\/msedge_dS9kJaGb5V.png\" alt=\"UI for an admin in view-based authorization\" width=\"840\" height=\"197\" srcset=\"https:\/\/code-maze.com\/wp-content\/uploads\/2024\/05\/msedge_dS9kJaGb5V.png 840w, https:\/\/code-maze.com\/wp-content\/uploads\/2024\/05\/msedge_dS9kJaGb5V-300x70.png 300w, https:\/\/code-maze.com\/wp-content\/uploads\/2024\/05\/msedge_dS9kJaGb5V-768x180.png 768w\" sizes=\"auto, (max-width: 840px) 100vw, 840px\" \/><\/a><\/p>\n<p>Here, we render different action buttons conditionally based on the user&#8217;s permissions, thus ensuring a controlled user experience where each user only sees what&#8217;s relevant to them.<\/p>\n<h2><a id=\"benefits\"><\/a>Benefits of View-Based Authorization<\/h2>\n<p>View-based authorization offers several advantages that enhance the flexibility and user experience of web applications.<\/p>\n<p>It allows us to dynamically control the visibility of UI elements based on a user&#8217;s permissions and roles. In other words, users only see the content they are authorized to access, leading to a more intuitive user interface.<\/p>\n<p>Because we embed the authorization logic directly into the client-side code, our application becomes more responsive, and the backend services are less complex. As the views become more self-contained with the authorization logic, it becomes easier to update authorization rules without impacting the overall application architecture.<\/p>\n<h2><a id=\"drawbacks\"><\/a>Drawbacks of View-Based Authorization<\/h2>\n<p>If our application depends solely on conditionally rendered view controls, a malicious user can easily bypass the authorization.\u00a0<\/p>\n<p>A &#8220;User&#8221; can potentially bypass view-based authorization by directly accessing URLs associated with edit or delete operations (such as <code>\/Edit?id=1<\/code> or <code>\/Delete?id=1<\/code>). This allows unauthorized users to perform actions that should be restricted based on their permissions.<\/p>\n<p>To mitigate this, we need to implement server-side authorization checks within the Razor pages associated with restricted operations, thus ensuring that access permissions are validated before allowing users to perform any actions.<\/p>\n<p>We can achieve this using the <code>[Authorize]<\/code> attribute:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">[Authorize(Policy = \"EditDocument\")]\r\npublic class EditModel : PageModel<\/pre>\n<p>This acts as an extra authorization measure to restrict access to the page for editing documents.<\/p>\n<h2><a id=\"conclusion\"><\/a>Conclusion<\/h2>\n<p>In this article, we learned how view-based authorization provides us with a mechanism for controlling user access to specific UI elements based on roles, claims, and policies. Also, we looked into the principles, implementation strategies, benefits, and drawbacks of this essential authorization mechanism.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>View-based authorization is an authorization strategy that enables us to manage UI elements&#8217; visibility based on the user&#8217;s identity. In this article, we&#8217;ll take a look at how we can achieve view-based authorization in an ASP.NET core application. Let&#8217;s begin. What Is Authorization? Before we dive deeper into the implementation of view-based authorization, let&#8217;s take [&hellip;]<\/p>\n","protected":false},"author":160,"featured_media":62187,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","footnotes":""},"categories":[2159],"tags":[79,74],"class_list":["post-116819","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-asp-net-core","tag-asp-net-core","tag-authorization","et-has-post-format-content","et_post_format-et-post-format-standard"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>View-Based Authorization in ASP.NET Core - Code Maze<\/title>\n<meta name=\"description\" content=\"View-based authorization is an authorization strategy that enables us to manage UI elements&#039; visibility based on the user&#039;s identity.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/code-maze.com\/aspnetcore-view-based-authorization\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"View-Based Authorization in ASP.NET Core - Code Maze\" \/>\n<meta property=\"og:description\" content=\"View-based authorization is an authorization strategy that enables us to manage UI elements&#039; visibility based on the user&#039;s identity.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/code-maze.com\/aspnetcore-view-based-authorization\/\" \/>\n<meta property=\"og:site_name\" content=\"Code Maze\" \/>\n<meta property=\"article:published_time\" content=\"2024-05-19T06:26:30+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-aspnetcore.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1100\" \/>\n\t<meta property=\"og:image:height\" content=\"620\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Satya Prakash\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@CodeMazeBlog\" \/>\n<meta name=\"twitter:site\" content=\"@CodeMazeBlog\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Satya Prakash\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":[\"Article\",\"BlogPosting\"],\"@id\":\"https:\/\/code-maze.com\/aspnetcore-view-based-authorization\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/code-maze.com\/aspnetcore-view-based-authorization\/\"},\"author\":{\"name\":\"Satya Prakash\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/person\/20cdbb4ac1a89e179194505db3eab0e7\"},\"headline\":\"View-Based Authorization in ASP.NET Core\",\"datePublished\":\"2024-05-19T06:26:30+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/code-maze.com\/aspnetcore-view-based-authorization\/\"},\"wordCount\":1318,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/code-maze.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/code-maze.com\/aspnetcore-view-based-authorization\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-aspnetcore.png\",\"keywords\":[\"asp.net core\",\"authorization\"],\"articleSection\":[\"ASP.NET Core\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/code-maze.com\/aspnetcore-view-based-authorization\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/code-maze.com\/aspnetcore-view-based-authorization\/\",\"url\":\"https:\/\/code-maze.com\/aspnetcore-view-based-authorization\/\",\"name\":\"View-Based Authorization in ASP.NET Core - Code Maze\",\"isPartOf\":{\"@id\":\"https:\/\/code-maze.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/code-maze.com\/aspnetcore-view-based-authorization\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/code-maze.com\/aspnetcore-view-based-authorization\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-aspnetcore.png\",\"datePublished\":\"2024-05-19T06:26:30+00:00\",\"description\":\"View-based authorization is an authorization strategy that enables us to manage UI elements' visibility based on the user's identity.\",\"breadcrumb\":{\"@id\":\"https:\/\/code-maze.com\/aspnetcore-view-based-authorization\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/code-maze.com\/aspnetcore-view-based-authorization\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/code-maze.com\/aspnetcore-view-based-authorization\/#primaryimage\",\"url\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-aspnetcore.png\",\"contentUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-aspnetcore.png\",\"width\":1100,\"height\":620,\"caption\":\"ASP.NET Core\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/code-maze.com\/aspnetcore-view-based-authorization\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/code-maze.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"View-Based Authorization in ASP.NET Core\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/code-maze.com\/#website\",\"url\":\"https:\/\/code-maze.com\/\",\"name\":\"Code Maze\",\"description\":\"Learn. Code. Succeed.\",\"publisher\":{\"@id\":\"https:\/\/code-maze.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/code-maze.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/code-maze.com\/#organization\",\"name\":\"Code Maze\",\"url\":\"https:\/\/code-maze.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png\",\"contentUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png\",\"width\":3511,\"height\":3510,\"caption\":\"Code Maze\"},\"image\":{\"@id\":\"https:\/\/code-maze.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/CodeMazeBlog\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/person\/20cdbb4ac1a89e179194505db3eab0e7\",\"name\":\"Satya Prakash\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2024\/05\/Satya-Prakash-400px-150x150.png\",\"contentUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2024\/05\/Satya-Prakash-400px-150x150.png\",\"caption\":\"Satya Prakash\"},\"description\":\"Satya is a seasoned full-stack developer with over 8 years of software development experience specializing in C#, JavaScript, Angular, and SQL. He has developed robust web applications and services, leveraging the .NET framework for backend development while integrating frontend frameworks to create dynamic user interfaces. Satya has a proven track record of leading successful projects, collaborating effectively with cross-functional teams, and delivering high-quality solutions. Committed to staying updated with the latest industry trends, he is passionate about leveraging his expertise to tackle complex challenges and contribute meaningfully to impactful projects.\",\"url\":\"https:\/\/code-maze.com\/author\/satya-prakash\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"View-Based Authorization in ASP.NET Core - Code Maze","description":"View-based authorization is an authorization strategy that enables us to manage UI elements' visibility based on the user's identity.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/code-maze.com\/aspnetcore-view-based-authorization\/","og_locale":"en_US","og_type":"article","og_title":"View-Based Authorization in ASP.NET Core - Code Maze","og_description":"View-based authorization is an authorization strategy that enables us to manage UI elements' visibility based on the user's identity.","og_url":"https:\/\/code-maze.com\/aspnetcore-view-based-authorization\/","og_site_name":"Code Maze","article_published_time":"2024-05-19T06:26:30+00:00","og_image":[{"width":1100,"height":620,"url":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-aspnetcore.png","type":"image\/png"}],"author":"Satya Prakash","twitter_card":"summary_large_image","twitter_creator":"@CodeMazeBlog","twitter_site":"@CodeMazeBlog","twitter_misc":{"Written by":"Satya Prakash","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":["Article","BlogPosting"],"@id":"https:\/\/code-maze.com\/aspnetcore-view-based-authorization\/#article","isPartOf":{"@id":"https:\/\/code-maze.com\/aspnetcore-view-based-authorization\/"},"author":{"name":"Satya Prakash","@id":"https:\/\/code-maze.com\/#\/schema\/person\/20cdbb4ac1a89e179194505db3eab0e7"},"headline":"View-Based Authorization in ASP.NET Core","datePublished":"2024-05-19T06:26:30+00:00","mainEntityOfPage":{"@id":"https:\/\/code-maze.com\/aspnetcore-view-based-authorization\/"},"wordCount":1318,"commentCount":0,"publisher":{"@id":"https:\/\/code-maze.com\/#organization"},"image":{"@id":"https:\/\/code-maze.com\/aspnetcore-view-based-authorization\/#primaryimage"},"thumbnailUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-aspnetcore.png","keywords":["asp.net core","authorization"],"articleSection":["ASP.NET Core"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/code-maze.com\/aspnetcore-view-based-authorization\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/code-maze.com\/aspnetcore-view-based-authorization\/","url":"https:\/\/code-maze.com\/aspnetcore-view-based-authorization\/","name":"View-Based Authorization in ASP.NET Core - Code Maze","isPartOf":{"@id":"https:\/\/code-maze.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/code-maze.com\/aspnetcore-view-based-authorization\/#primaryimage"},"image":{"@id":"https:\/\/code-maze.com\/aspnetcore-view-based-authorization\/#primaryimage"},"thumbnailUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-aspnetcore.png","datePublished":"2024-05-19T06:26:30+00:00","description":"View-based authorization is an authorization strategy that enables us to manage UI elements' visibility based on the user's identity.","breadcrumb":{"@id":"https:\/\/code-maze.com\/aspnetcore-view-based-authorization\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/code-maze.com\/aspnetcore-view-based-authorization\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/code-maze.com\/aspnetcore-view-based-authorization\/#primaryimage","url":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-aspnetcore.png","contentUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-aspnetcore.png","width":1100,"height":620,"caption":"ASP.NET Core"},{"@type":"BreadcrumbList","@id":"https:\/\/code-maze.com\/aspnetcore-view-based-authorization\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/code-maze.com\/"},{"@type":"ListItem","position":2,"name":"View-Based Authorization in ASP.NET Core"}]},{"@type":"WebSite","@id":"https:\/\/code-maze.com\/#website","url":"https:\/\/code-maze.com\/","name":"Code Maze","description":"Learn. Code. Succeed.","publisher":{"@id":"https:\/\/code-maze.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/code-maze.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/code-maze.com\/#organization","name":"Code Maze","url":"https:\/\/code-maze.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/code-maze.com\/#\/schema\/logo\/image\/","url":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png","contentUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png","width":3511,"height":3510,"caption":"Code Maze"},"image":{"@id":"https:\/\/code-maze.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/CodeMazeBlog"]},{"@type":"Person","@id":"https:\/\/code-maze.com\/#\/schema\/person\/20cdbb4ac1a89e179194505db3eab0e7","name":"Satya Prakash","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/code-maze.com\/#\/schema\/person\/image\/","url":"https:\/\/code-maze.com\/wp-content\/uploads\/2024\/05\/Satya-Prakash-400px-150x150.png","contentUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2024\/05\/Satya-Prakash-400px-150x150.png","caption":"Satya Prakash"},"description":"Satya is a seasoned full-stack developer with over 8 years of software development experience specializing in C#, JavaScript, Angular, and SQL. He has developed robust web applications and services, leveraging the .NET framework for backend development while integrating frontend frameworks to create dynamic user interfaces. Satya has a proven track record of leading successful projects, collaborating effectively with cross-functional teams, and delivering high-quality solutions. Committed to staying updated with the latest industry trends, he is passionate about leveraging his expertise to tackle complex challenges and contribute meaningfully to impactful projects.","url":"https:\/\/code-maze.com\/author\/satya-prakash\/"}]}},"_links":{"self":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts\/116819","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/users\/160"}],"replies":[{"embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/comments?post=116819"}],"version-history":[{"count":3,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts\/116819\/revisions"}],"predecessor-version":[{"id":116825,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts\/116819\/revisions\/116825"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/media\/62187"}],"wp:attachment":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/media?parent=116819"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/categories?post=116819"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/tags?post=116819"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}