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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T23:04:20+00:00 2026-05-20T23:04:20+00:00

I have an MVC application with the following block inside in Web.config: <authentication mode=Forms>

  • 0

I have an MVC application with the following block inside in Web.config:

<authentication mode="Forms">
    <forms loginUrl="~/Login" timeout="2880" />
</authentication>

So, if a user requests a page and authorization fails, they will be redirected to ~/Login.

That’s fine, and I need it for most of my controllers. However, I have a controller which I’d like to bypass this rule with. How can I allow specific controllers to ignore this rule?

My problem is that in my MVC application (which has several controllers), I have a certain controller which hosts a REST interface (not meant for browser use). Since this controller isn’t meant for browser-consumption, I don’t want it sending back an entire login page, (or any page whatsoever actually, just strings or partial views.)

Note that I’m using custom [Authorize…] attributes on my actions, and when THESE fail, they redirect to an Error action–but, unfortunately, my Error action (which returns a short string) is being redirected to the Login page because of this configuration setting!

I’m getting dizzy trying to figure this out, what am I doing wrong? I can provide more details if necessary.

  • 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-20T23:04:21+00:00Added an answer on May 20, 2026 at 11:04 pm

    You could extend the AuthorizeAttribute class and override HandleUnauthorizedRequest, you may want to return a Forbidden http status code rather than a custom message.

    public class CustomAuthorizationAttribute : AuthorizeAttribute
    {
        protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext)
        {
            // You need to set this action result to something other than a HttpUnauthorizedResult, 
            // this result will cause the redirection to the login page
    
            // Forbidden request... does not redirect to login page
            // filterContext.Result = new HttpStatusCodeResult(403);
    
            filterContext.Result = new ErrorActionResult { ErrorMessage = "Unauthorized Access" };
        }
    }
    
    public class ErrorActionResult : ActionResult
    {
        public string ErrorMessage { get; set; }
    
        public override void ExecuteResult(ControllerContext context)
        {
            context.HttpContext.Response.Write(this.ErrorMessage);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have deployed an ASP.NET MVC application following the article How to: Deploy an
I have the following issue: I have a MVC application, in some action of
I have a simple Spring MVC application with a REST-like web service. When I
I have _Layout.cshtml defined for my mvc application, which is shown below: @inherits System.Web.Mvc.WebViewPage
I have an MVC application that among other things contains a small Silverlight menu
I have an .Net MVC application which runs fine if I use the build
I have an ASP.NET MVC-application which I want deployable on both IIS6 and IIS7
I have an asp.net mvc application with a route similar to: routes.MapRoute(Blog, {controller}/{action}/{year}/{month}/{day}/{friendlyName}, new
I have an ASP.NET MVC application, when a user clicks on the submit button
I have an asp.net mvc application and i am trying to assign value to

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.