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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T14:29:04+00:00 2026-06-03T14:29:04+00:00

I have a mvc 3 project and I use AD to authorise users. I

  • 0

I have a mvc 3 project and I use AD to authorise users.
I have a page where only users with the role “Admin” should have access.

I’ve made the sign in working and authorise users so only admins can acces the admin part of the site.
The problem I have is when a users is not admin, I seem to be unable to show a good error message.

Here is my actionFilterattribute

public class AdminOnlyAttribute : ActionFilterAttribute
{
    public override void OnActionExecuting(ActionExecutingContext filterContext)
    {
        base.OnActionExecuting(filterContext);
        bool isAuthorised = false;

        IPrincipal user = filterContext.HttpContext.User;
        if (user.Identity.IsAuthenticated)
        {
            if (user.IsInRole("Admin"))
            {
                isAuthorised = true;
            }
        }

        if (!isAuthorised)
        {
            //error message here
        }
    }

And this is my controller for admin

    [AdminOnly]
        public ActionResult Index()
        {
        //admin stuff
        }

Any help is appreciated, thanks in advance

  • 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-03T14:29:05+00:00Added an answer on June 3, 2026 at 2:29 pm

    If the isAuthorised is false, you’ll need to take them to a page where you can display a “You do not have access to the page etc.”. To do the redirect, you must do the following (in my example I’m redirecting them to Account/AccessDenied that will return a view containing a message saying “You do not have access etc…”:

    if (!isAuthorised)
    {
        filterContext.Result = new RedirectToRouteResult(
            new RouteValueDictionary {{"action", "AccessDenied"}, 
                {"controller", "Account"}});
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a MVC 3 project in which I use _Layout.cshtml as master page
I have started a new mvc project and clicked on project\properties\web - use local
I have an ASPNET MVC 2 project. When I use <%= Html.TextBoxFor(model => model.Login)
I'm trying to use derobins wmd editor, with ASP.NET MVC 3 Project. I have
I have a mvc project and on one page there is a table of
I have a MVC 4 project I am currently working on and need some
I am working on a MVC project where I have copied a lot of
I have .NET MVC 3 project where I use sql membership provider and entity
I have created a servicestack MVC project, this I use as the main API
In an MVC project, I have an ActionLink, which, when clicked, should take an

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.