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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:20:13+00:00 2026-05-28T07:20:13+00:00

After asking this question about authorization, I’ve added a new custom attribute in an

  • 0

After asking this question about authorization, I’ve added a new custom attribute in an attempt to redirect unauthorised users to a page which has more details on requesting access etc etc.

public class RedirectAuthorize:AuthorizeAttribute
    {
        protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext)
        {
            //base.HandleUnauthorizedRequest(filterContext);

            filterContext.Result = new RedirectResult("Unauthorized");
        }
    }

I’ve decorated my Home controller with this attribute and the correct (Role=”…”) and this “works”..i.e. it hits the method as and when expected.

I’ve added a vanilla view to the Shared views folder called Unauthorized.cshtml but I just get “The resource cannot be found” 404 error.

The URL displayed appears to be correct?

My guess is I need to specify a controller/action instead of a page? but the Error handler redirects to Error.cshtml without needing a controller?

Thanks for any assistance.

  • 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-28T07:20:14+00:00Added an answer on May 28, 2026 at 7:20 am

    Problem is you are using RedirectResult which forces the browser to request the given URL. But when the browser requests it there is no route that matches. Hence it throws a 404 error.

    Try

    filterContext.Result = new ViewResult { ViewName = "Unauthorized" };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After asking this question about interface fields in records I assumed that the following
After asking this question and apparently stumping people, how's about this for a thought--
After asking this question yesterday about branching in mercurial, I've decided to try out
After asking this question I was advised not to check in binaries into subversion.
After my last, failed, attempt at asking a question here I'm trying a more
After asking this question ( XAMPP Mercurial installation on Windows Apache --> HgWebDir.cgi Script
After asking a question about sending 304 Not Modified for images stored in the
Please note that this is asking a question about constructors, not about classes which
I understand that this question is similar to others asking about Java Properties, and
Hello yeah I'm asking this question a second time, sorry about that but I

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.