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

The Archive Base Latest Questions

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

So I want to create a login page where when you enter your login

  • 0

So I want to create a login page where when you enter your login credentials as a admin you get acces. If you are not a admin you get redirected back to the login page. In my database I have a field of boolean type:

isAdmin <--datatype(byte")

So how can you the best way do this?! I would like to do this in the repository pattern way as it gets easier to unit test it then.

I have googled this a lot and starting to get a bit confused on the matter. How many classes, models etc should I have?! I’m guessing one controller would do. Anyone got any good ideas?! I’ve read some on the DCI pattern about user roles but as it basically “only” to check that boolean in the database maybe it is overkill? Thankful for all feedback.

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

    If I understand correctly, I had a similar issue. It seems from your question that you are not using the default membership provider (at least as is). I didn’t either. So what I did was create a new authorization attribute. In your case it could look something like this:

    public class AdminOnlyAttribute : AuthorizeAttribute {
        IUserRepository _UserRepository;
    
        public SimpleUser SimpleUser { get; set; }
    
        public AdminOnlyAttribute() {
            _UserRepository = new SqlUserRepository(new DbContext());
        }
    
        protected override bool AuthorizeCore(HttpContextBase httpContext) {
            bool baseAuthorized = base.AuthorizeCore(httpContext);
            if (!baseAuthorized) {
                return false;
            } 
    
            //Here you use your repository to check if a user is an admin or not
            bool isAdmin = _UserRepository.IsAdmin(int.Parse(httpContext.User.Identity.Name));
    
            if (!isAdmin) {
                return false;
            }
    
            return true;
        }
    }
    

    The repository method IsAdmin could be as simple as a query to check the boolean corresponding to the supplied user’s ID. Something like this (please double check if SingleOrDefault() is necessary or not):

    public bool IsAdmin(int userID) {
        bool isAdmin = (from user in db.Users
                        where user.ID == userID
                        select user.isAdmin).SingleOrDefault();
        return isAdmin;
    }
    

    And then use this in the action you want like so:

    [AdminOnly]
    public ActionResult Index(){
        //Code here...
    }
    

    When this returns false, your ActionResult will be an HttpUnauthorizedResult which in theory should redirect to the login page.

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

Sidebar

Related Questions

I'm creating a login page. I want to create ASP.NET TextBox controls that have
Hi I want to create a WCF service that have login method, which is
I want to create a login page, it can easy implement using Ruby on
I want to create a login page using Servlet & JSP. I ve created
I am new to node.js and want to create a registration and login page
i have created a login page for some application in android and i want
I use DotNetOpenAuth in my Asp.Net application. I want to create a login page
I want to create a agenda, where you just have to login into CMS
I would like to create a login page using ASP.NET. I don't want to
I am creating a login page for my web application. I want to create

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.