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 7883393
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T04:31:12+00:00 2026-06-03T04:31:12+00:00

I have a site with links throughout it for performing actions. Some need to

  • 0

I have a site with links throughout it for performing actions. Some need to be hidden if the user is not in the admin role. I am doing checking on the backend just in case someone types i n the url directly etc. but is it enough to have this in the razor view?

<ul>
<li>Home</li>
<li>Items</li>
@if(User.IsInRole("Admin"){
    <li>Users</li>
}
</ul>
  • 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-03T04:31:14+00:00Added an answer on June 3, 2026 at 4:31 am

    Yep, that is sufficient.

    Or as I found in another post which i used lately:

    public static MvcHtmlString If(this MvcHtmlString value, bool evaluation)
    {
         return evaluation ? value : MvcHtmlString.Empty;
    }
    

    so you can use this:

    @Html.ActionLink("Create New", "Create").If(User.IsInRole("Admin"))
    

    However, if you are using links to other pages which you need to prevent from accessing when not in a specific role. You should also include the Authorize attribute in the controllers you want to prevent them from accessing:

    public class HomeController : Controller
    {
        [Authorize(Roles="Admin")]
        public ActionResult Index()
        { 
            return View();
        }
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have textarea in my site(link shortening site) i want to user enter some
I have used absolute links throughout my site, the problem comes when I am
I have a site where I need to check all href-links if they are
I have in my site some links that are just used to display informative
So I have site list on certain pages that basically just have links to
Let's say I have a site with multiple links as follows: www.example.com/product/1 www.example.com/product/2 www.example.com/product/3
I have a web site that spits out links to third party sites. Now
For technical reasons on a site we may have two or more links that
I have third party sites that link to some images on my site. The
I have a site that shortens links based on Noah Hendrix's tutorial on the

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.