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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:07:02+00:00 2026-05-25T06:07:02+00:00

I am trying to create an access denied ActinoResult to return from my controllers.

  • 0

I am trying to create an access denied ActinoResult to return from my controllers. I have the following implementation

public class AccessDeniedResult : ActionResult
{
    public override void ExecuteResult(ControllerContext context)
    {
        if (null != context && null != context.HttpContext && null != context.HttpContext.Response)
        {
            context.HttpContext.Response.StatusCode = 401;
            context.HttpContext.Response.RedirectToRoute("AccessDenied");
        }
    }
}

This does not work because of a NotImplementedException coming from HttpResponseBase being passed as context.HttpContext.Response.

How do you write a correct redirecting action result in MVC3?

  • 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-25T06:07:03+00:00Added an answer on May 25, 2026 at 6:07 am

    You should be returning HttpUnauthorizedResult like so:

    return new HttpUnauthorizedResult();
    

    Additionally, you should consider creating a new class deriving from AuthorizeAttribute to do security checks. You can then add this directive to your web.config to control where the client is directed:

    <customErrors mode="On" defaultRedirect="~/Home/Error">
        <error statusCode="401" redirect="~/AccessDenied" />
    </customErrors>
    

    Finally, you can add a custom route to control what happens when the user is directed to ~/AccessDenied:

    Route route = routes.MapRoute("AccessDeniedRoute", "AccessDenied", new { controller = "MyCustomErrorController", action = "My401Action" });
    RouteTable.Routes.Add(route);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to programmatically create a PowerPoint from graphs in Access. Ideally, when
I'm trying to create a csv export of data from mysql using the following
I'm trying to create an access control system. Here's a stripped down example of
I am trying to create a data access layer using t4 and C#. I
I am trying to create a recordset in Access VBA that will show me
I'm trying to create a DLL using a Dataset.XSD file to access my website's
I am trying to create a function that will block access to some of
I am trying to create a check constraint on an access (jet?) table. So,
I am trying to import an access database to mysql. I have created a
I'm trying to access list data using SSRS 2008. I have created an XML

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.