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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T12:10:10+00:00 2026-05-12T12:10:10+00:00

By default, the MVC Authorize attribute sets the HttpContext.Response.StatusCode = 401 when a user

  • 0

By default, the MVC Authorize attribute sets the HttpContext.Response.StatusCode = 401 when a user is not authorized and the section in the web.config routes to the loginUrl property.

I want to do something similar with other response codes. For example, I have an attribute called ActiveAccount which verifies the user’s account is currently active and then allows them access to the controller. If they are not active I want to route them to a specific controller and view (to update their account).

I’d like to copy the Authorize attributes way of handling this and set the StatusCode to something like 410 (warning: preceding number pulled out of thin air) and have the user routed to a location defined in the web.config file.

What can I do to implement this behavior? Or is there a simpler method?

Edit: Results

I ended up avoiding the StatusCode and just performing a redirection from within the attribute as this was much simpler. Here is my code in a nutshell:

// using the IAuthorizationFilter allows us to use the base controller's 
//   built attribute handling.  We could have used result as well, but Auth seems
//   more appropriate.
public class ActiveAccountAttribute: FilterAttribute, IAuthorizationFilter
{

    #region IAuthorizationFilter Members

    public void OnAuthorization(AuthorizationContext filterContext)
    {

        if (!filterContext.HttpContext.User.Identity.IsAuthenticated)
            return;

        // ... code which determines if our customer account is Active

        if (!user.Status.IsActive)
            filterContext.Result = new RedirectToRouteResult("Default", new RouteValueDictionary(new {controller = "Account"}));
    }

    #endregion
}
  • 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-12T12:10:10+00:00Added an answer on May 12, 2026 at 12:10 pm

    You could inherit the RedirectToRouteResult class and add a constructor parameter for the status code.

    public class StatusRedirectResult : RedirectToRouteResult
    
        private string _status;
    
        public StatusRedirectResult(string action, RouteValueDictionary routeValues, string statusCode)
        {
            _status = statusCode;
            base.RedirectToRouteResult(action, routeValues);
        }
    
        public override ExecuteResult(ControllerContext context)
        {
            context.HttpContext.Current.Response.Status = _status;
            base.ExecuteResult(context);
        }
    }
    

    To use this in a controller action, just

    return StatusRedirect("NewAction", new RouteValueDictionary(new { controller = "TheController" }, "410");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 208k
  • Answers 208k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The dot . does not match newlines unless you use… May 12, 2026 at 9:28 pm
  • Editorial Team
    Editorial Team added an answer The other answers evince a mild confusion as to how… May 12, 2026 at 9:28 pm
  • Editorial Team
    Editorial Team added an answer How about using the tablesorter plugin or looking at the… May 12, 2026 at 9:28 pm

Related Questions

[Edit: Apparently, this is only an issue for arrays and FoxyBOA's answer might direct
By default the MVC Preview 5 web project comes with a HomeController.vb class. This
I have Elmah up and running in my ASP.NET MVC site and I would
If a view needs to acces data from a model, do you think the

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.