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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:18:17+00:00 2026-06-12T16:18:17+00:00

While using mvc intranet template with domain authorization, how can I redirect to some

  • 0

While using mvc intranet template with domain authorization, how can I redirect to some certain error page on authorization failure depending on the controller?

So, I have a controller class:

    [AuthorizeWithRedirect(Users = @"user")]
    public class MyController : Controller
    {
    ...
    }

By default I’m not redirected anywhere. I see only a blank page, if I open the page under another user. The issue is that I want the request to be redirected to different pages for different controllers if the authorization fails. That is, one page for MyController, another page for other controller, etc.

I know I could derive from AuthorizeAttribute and override HandleUnauthorizedRequest method. But I can’t make it work:

public class AuthorizeWithRedirect : AuthorizeAttribute
{
   protected override void HandleUnauthorizedRequest(AuthorizationContext context)
   {
       UrlHelper urlHelper = new UrlHelper(context.RequestContext);
       context.Result = new RedirectResult(urlHelper.Action("MyErrorPage"));
   }
}

I get an error, saying that the specified url is not found, while MyErrorPage.cshtml does present in the Views\Shared folder.

EDIT

    [Authorize(Users = @"user")]//should be redirected to ErrorPage1
    public class MyController1 : Controller
    {
    ...
    }

while

    [Authorize(Users = @"user")]//should be redirected to ErrorPage2
    public class MyController2 : Controller
    {
    ...
    }

That is, different error pages for different controllers on one and the same authorization failure

  • 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-06-12T16:18:19+00:00Added an answer on June 12, 2026 at 4:18 pm

    The AuthorizeWithRedirect looks good.
    But MVC is complaining that you do not have right action method.

    The view is not an issue here. The controller and action method is.

    Try something like this:

    context.Result = new RedirectResult(urlHelper.Action("Test", "Redirect"));
    

    With present TestController with an public action method Redirect.

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

Sidebar

Related Questions

I'm getting the following error, while using ExtJs MVC, Uncaught TypeError: Cannot call method
I was thinking of using mvc pattern while designing this app. How can I
I am using Telerik MVC grid ajax binding to show some records. While the
AuthorizeAttribute is useless while using ServiceStack.Mvc AuthenticateAttribute is for DTO objects. There is no
I'd like to implement MVC while using LINQ (specifically, LINQ-to-entities). The way I would
I'd like to use socketstream's RPC over websockets abstraction while using Angular for MVC.
i am using mvc 3 code first. facing problem while passing data form SecurityAttribute
I'm using .NET 3.5 SP1 in ASP.NET MVC application. While using ObjectContext with Http
I've been using ASP.NET MVC for a little while now and seem to find
In my asp.net MVC app, I'm using a HTML text input, while I apply

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.