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

  • Home
  • SEARCH
  • 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 7194903
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:28:11+00:00 2026-05-28T20:28:11+00:00

I am trying to make it easier to the developer, Because there are multiple

  • 0

I am trying to make it easier to the developer,
Because there are multiple options of Authentication, and not all pages require authentication or full authentication.

In WebForms I can have a generic page,
Now each page inherits GenericPage, and only need to implemenet AuthorizationType (see code below)

Can I do anything similiar with Razor?
Or maybe I should somthing entirely different…

Here is the code in WebForms:

public class GenericPage : Page
{
    public enum AuthorizationType
    {
        Users = 1,
        AuthUsers = 2,
        Admins = 4
    }

    public virtual bool IsAuth()
    {
        return Authenticator.IsAuth();
    }

    public virtual bool IsAdmin()
    {
        AuthUser authUser = Authenticator.GetAuthenticatedUser();
        return (authUser != null && authUser.IsAdmin)
    }

    protected abstract AuthorizationType Authorization
    {
        get;
    }

    protected virtual string OnAuthorizationFailedUrl
    {
        get
        {
            return HomePageUrl;
        }
    }

    protected void CheckAuthentication()
    {
        if (!IsUserAuthroized())
            Response.Redirect(OnAuthorizationFailedUrl);
    }

    protected bool IsUserAuthroized()
    {
        AuthorizationType authorization = Authorization;
        return (Authorization.Contains(AuthorizationType.Users) ||
                (Authorization.Contains(AuthorizationType.AuthUsers) && IsAuth()) ||
                (Authorization.Contains(AuthorizationType.Admins) && IsAdmin()));
    }

    override OnPageLoad()
    {
        CheckAuthentication();
    }
}

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-05-28T20:28:12+00:00Added an answer on May 28, 2026 at 8:28 pm

    You can add this type of authorization as a global filter.

    Filtering in asp.net mvc

    http://bradwilson.typepad.com/blog/2010/07/service-location-pt4-filters.html

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

Sidebar

Related Questions

I'm trying to split an app.config file into multiple files to make it easier
I am trying to make saving and loading easier for some GUIs that I've
I'm trying to extend the DOMDocument class so as to make XPath selections easier.
I'm trying to solve a problem that anonymous functions make much, much easier, and
I'm trying to make a BASIC roulette script. Is there anyway to get the
I am trying to make my game a bit easier on the phone, so
I'm trying to make my life easier by making a script that generates HTML
I am trying to make an Android music player. To make things easier, I
I'm trying to make debugging our Fitnesse tests easier. We're using runnerw.exe for debugging,
I'm trying to create a small javascript framework that can make it easier when

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.