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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:30:01+00:00 2026-05-22T16:30:01+00:00

How do I lock down a controller class to only be accessible by one

  • 0

How do I lock down a controller class to only be accessible by one or more roles? I’ve tried using the AuthorizeAttribute in my second example, but it seems to force authorization to be requested, instead of granting access to the page.

[PrincipalPermission(SercurityAction.?????????)]
public class MySecuredController { ...

OR

[Authorize(Roles="MyRoleName")
public class MySecuredController { ...

OR

Am I completely wrong?

Whole script it is really just the MVC3 tutorial…

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.IO;
using System.Security.Permissions; 

namespace mvc3test.Controllers
{
    [Authorize(Roles="taxpayer")]
    public class HomeController : Controller
    {

        public ActionResult Index()
        {
            ViewBag.Message = "Welcome to ASP.NET MVC!";
            return View();
        }

        public ActionResult About()
        {
            return View();
        }

        [HttpPost]
        public ActionResult Index(HttpPostedFileBase dr405)
        {
            var saveLocation = Path.Combine(Server.MapPath("\\"),"returns");
            System.IO.Directory.CreateDirectory(saveLocation);
            dr405.SaveAs(Path.Combine(saveLocation,User.Identity.Name) + ".xlsx");
            ViewBag.Message = String.Format("File name: {0}, {1}Kb Uploaded Successfully.",dr405.FileName,(int)dr405.ContentLength / 1024); 
            return View();
        }

    }
}

when I run this the site logs me in after entering my credentials. I know this because my name appears in the upper right corner of the screen. But It just keeps taking my to the login screen over and over and over.

Update

So I added a watch to the Redirect Method in the LogOn Action for the value of User.IsInRole("taxpayer") where User.Identity.Name is the username in question. User.IsInRole("taxpayer") returned false. Below when I run the aspnet_db stored proc, it indicates the user in the list returned…..

USE [aspnetdb]
GO

DECLARE @return_value int

EXEC    @return_value = [dbo].[aspnet_UsersInRoles_GetUsersInRoles]
        @ApplicationName = N'/',
        @RoleName = N'taxpayer'

SELECT  'Return Value' = @return_value

GO

So now I’m wondering if it is a data issue. Any thoughts???

  • 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-05-22T16:30:02+00:00Added an answer on May 22, 2026 at 4:30 pm

    If the user accessing the page is either not authenticated or not a member of the given role (your second option is the one I use) then they will be redirected to the authentication page. This is a filter, not a grant.

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

Sidebar

Related Questions

I have a requirement to lock down access to a SharePoint library: Only users
I have a VPS server and I lock down to only expose 3 ports
I am attempting to lock down a page to only accept POST requests. as
I need to be able to lock down the valid characters in a textbox,
I'm trying to lock down my understanding of proper memory management within Objective-C. I've
I'm trying to build an application that needs to lock down access to the
We're trying to lock down a computer such that we have a generic login
Is there a way to lock down the security of a SSRS report by
I am developing a desktop application and would like to lock down certain parts
I'm starting a Java project and need a way to completely lock down a

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.