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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:16:41+00:00 2026-05-26T20:16:41+00:00

I was trying to figure out whether it would be possible to present two

  • 0

I was trying to figure out whether it would be possible to present two different login screens based on the authorization role. The requirement is simple. I have two roles say “admin” and “public”. There are “Authorize” attributes marked all over my applications action methods for these two roles.

Now the requirements of my application specifies different login screens for “admin” and “public”. The “admin” login screen is secured by an additional security code which is not required for “public” login screen. What I was looking for is some way to know who is trying to log in based on the Action method invoked. If the action method invoked is decorated by Authorize[Roles="admin"] then I would present the admin login screen, whereas if action method invoked is applied Authorize[Roles="public"] then I need to present the public login screen.

If the Login Screen is directly invoked then by default the public login screen would be presented.

It may sound a little weird but this is the scenario I am trying to figure out the solution for.

  • 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-26T20:16:42+00:00Added an answer on May 26, 2026 at 8:16 pm

    You could write a custom authorize attribute which will redirect to the proper logon action:

    public class MyAuthorizeAttribute : AuthorizeAttribute
    {
        protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext)
        {
            var roles = Roles.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            if (roles.Contains("admin", StringComparer.OrdinalIgnoreCase))
            {
                filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(new
                {
                    controller = "account",
                    action = "adminlogon",
                    returnUrl = filterContext.HttpContext.Request.RawUrl
                }));
            }
            else
            {
                filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(new
                {
                    controller = "account",
                    action = "logon",
                    returnUrl = filterContext.HttpContext.Request.RawUrl
                }));
            }
        }
    }
    

    and then decorate your controllers/actions with it:

    [MyAuthorize(Roles = "admin")]
    public ActionResult Foo()
    {
        return View();
    }
    
    [MyAuthorize(Roles = "normaluser")]
    public ActionResult Bar()
    {
        return View();
    }
    

    Now if a non authenticated user tries to hit the Foo action he will be redirected to the /account/adminlogon action and if he tries to hit the Bar action he would be redirected to the /account/logon action. In both cases the current url will be passed as returnUrl parameter so that upon successful login the user could be brought to the page that he was initially trying to browse.

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

Sidebar

Related Questions

In the course of trying to figure out whether it's possible to contain text
I'm trying to figure out whether it's possible to implement the following Mathematica interface.
I have been trying to figure out whether it is possible to use only
I'm trying to figure out whether it is possible to define view navigators and
I'm learning Backbone.js and am trying to figure out whether it's possible to have
I'm trying to figure out whether it would be worthwhile to spread image requests
I am trying to figure out whether or not the current date falls within
I’m trying to figure out whether FormsAuthentication.RedirectFromLoginPage (called inside method M() ), performs redirection
I'm working on a little something and I am trying to figure out whether
I'm a Java newbie. I'm trying to figure out whether a number is 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.