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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:31:21+00:00 2026-05-27T19:31:21+00:00

I am thoroughly stumped on this one. Basically, I have an MVC page with

  • 0

I am thoroughly stumped on this one. Basically, I have an MVC page with a custom AuthorizeAttribute that throws a 403 error if a user is authenticated, but does not have appropriate access. The problem I am having is that I would like to redirect this error to a custom controller/action (/Error/Unauthorized).

I have added the following in my web.config

<httpErrors errorMode="Custom">
  <remove statusCode ="403" subStatusCode="-1"/>
  <error statusCode="403" path="/Error/Unauthorized" responseMode="ExecuteURL" />
</httpErrors>

With the above configuration, I do not see the default IIS 7.5 403 redirect. However, I also do not see anything. In IE, it tells me that the website requires you to login and chrome just shows me a blank page.

Any ideas?

Here is the custom authorization code in case that might help

    public class CustomAuthorize : AuthorizeAttribute
    {
        //Property to allow array instead of single string.
        private string[] _authorizedRoles;

        public string[] AuthorizedRoles
        {
            get { return _authorizedRoles ?? new string[0]; }
            set { _authorizedRoles = value; }
        }

        protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext)
        {
            base.HandleUnauthorizedRequest(filterContext);
            if (filterContext.HttpContext.Request.IsAuthenticated)
            {
                filterContext.HttpContext.Response.TrySkipIisCustomErrors = true;
                filterContext.Result = new HttpStatusCodeResult(403);
            }
        }

        protected override bool AuthorizeCore(HttpContextBase httpContext)
        {
            if (httpContext == null)
                throw new ArgumentNullException("httpContext");

            if (!httpContext.User.Identity.IsAuthenticated)
                return false;

            //Check to see if any of the authorized roles fits into any assigned roles only if roles have been supplied.
            if (AuthorizedRoles.Any(httpContext.User.IsInRole))
                return true;

            return false;
        }
    }
  • 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-27T19:31:21+00:00Added an answer on May 27, 2026 at 7:31 pm

    OK, I am not sure if this is truly correct or not, but it fits my symptoms. http://forums.asp.net/t/1462153.aspx/1
    I am not happy that I have to code the redirect, but I tried to make it at least explicit for future maintainability.

        public bool RedirectAuthenticatedButUnauthorizedUsers { get; set; }
    
        private String _redirectUnauthorizedUrl = String.Empty;
        public String RedirectUnauthorizedUrl
        {
            get { return _redirectUnauthorizedUrl; }
            set { _redirectUnauthorizedUrl = value.Trim(); }
        }
    
        protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext)
        {
            base.HandleUnauthorizedRequest(filterContext);
            if (!RedirectAuthenticatedButUnauthorizedUsers || !filterContext.HttpContext.Request.IsAuthenticated)
                return;
            if(RedirectUnauthorizedUrl == String.Empty)
                throw new NullReferenceException("RedirectAuthenticatedButUnauthorizedUsers " +
                                                 "set to true, but no redirect URL set.");
            filterContext.HttpContext.Response.Redirect(RedirectUnauthorizedUrl);
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm thoroughly stumped by this one. I have a static class which manages a
This section has me thoroughly confused. I have an example problem that I am
Okay, I'm thoroughly stumped on this one. I'm trying to build a menu of
I have read this page quite thoroughly: http://datamapper.org/docs/associations If the answer is on there,
First let me say I have read this useful article thoroughly and am using
I have an .ocx/ActiveX library that I coded in Delphi. I have thoroughly tested
I have searched quite thoroughly on this but can't seem to find an answer.
Eric Lippert's comments in this question have left me thoroughly confused. What is the
One of the things that get me thoroughly confused is the use of session.Flush
I have a utility class that has been thoroughly tested, and I do not

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.