Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9152743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:07:47+00:00 2026-06-17T12:07:47+00:00

I am looking to create a security trimmed (basically if you don’t have permission

  • 0

I am looking to create a security trimmed (basically if you don’t have permission don’t render) Html.RenderAction.

The aim is to display various widgets/page components and if the person doesn’t have permission on the action the RenderAction doesn’t get called (or at least doesn’t cause a re-direct to login page). For example the page is shown to all logged in users. However there will be parts that are only for HR, Business Development and if you are in HR and Business development you would get both parts etc.

Each part called by RenderAction is stand-alone so it means I can easily make pages that contain all the required parts but then they just don’t display if the user isn’t permitted. If I call RenderAction on for an action someone doesn’t have permission to then it causes them to get re-directed to login page.

I have seen something similar done with links but as anyone done anything similar for Actions?

I was hoping to get something like:

@Html.RenderSecurityTrimmedAction("Main","Business-Widget1")
@Html.RenderSecurityTrimmedAction("Main","HR-Widget")
@Html.RenderSecurityTrimmedAction("Main","General-Widget3")

Where Widget access is based on the persons current role. I have security access working perfectly. It’s mainly creating a RenderAction that doesn’t uncenssarily run the Action if the user doesn’t have perission

I want to keep the code DRY so I don’t want to be carrying lots of ViewModel properties and then having to wrap every Html.RenderAction in an if statement. These components will appear in a variety of places so I want them to be plug and play.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T12:07:48+00:00Added an answer on June 17, 2026 at 12:07 pm

    I implemented the following:

        public static void SecurityTrimmedRenderAction(this HtmlHelper htmlHelper,
                                                      ActionResult actionResult)
        {
            var routeValueDictionary = actionResult.GetRouteValueDictionary();
            var actionName = (string)routeValueDictionary["Action"];
            var controllerName = (string)routeValueDictionary["Controller"];
            //var areaName = (string)routeValueDictionary["Area"];
            var hasActionPermission = SecurityTrimmingExtensions.HasActionPermission(htmlHelper, actionName,
                                                                                     controllerName);
            if (hasActionPermission)
            {
                htmlHelper.RenderAction(actionResult);
            }
        }
    

    The SecurityTrimmingExtensions follows the code found here: ASP.Net MVC how to determine if a user can access a URL?

    I don’t have to touch Authorize doing it this way as the code isn’t called if the current user doesn’t have permissions

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking to create something like in this image. Each block would have an
I'm looking to create a table in html to be used to insert the
I'm currently looking into unit testing for a new application I have to create.
I am looking for a Spring Security LDAP tuturial. The few tutorials I have
Basically I'm looking to create a page using PHP that will take SQL input,
I looking to create a custom calender with Zend Framework, I am hoping that
Im looking to create a control that would look like comic baloon. In WPF
I'm looking to create a portfolio using a Wordpress blog. On the summary page
I am looking to create a reg ex in JS that obtains 2 values
I'm looking to create a command line menu in powershell, with the options coming

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.