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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:56:04+00:00 2026-05-25T12:56:04+00:00

I have a custom action filter (AuthenticateAttribute) in my ASP.NET MVC 3 application that

  • 0

I have a custom action filter (AuthenticateAttribute) in my ASP.NET MVC 3 application that ensures that users are logged in.

I want to raise exceptions in the OnActionExecuting method and would like those to be handled by the HandleError global filter. Is that possible and, if so, how do I do it?

Currently, raising an exception in OnActionExecuting bypasses the HandleError global filter – presumably because that only traps exceptions that occur within the action iself.

  • 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-25T12:56:04+00:00Added an answer on May 25, 2026 at 12:56 pm

    Exceptions thrown in the OnActionExecuting will be handled by the global HandleErrorAttribute. You just need to ensure that in your web.config you have enabled it:

    <customErrors mode="On" />
    

    This being said you talked about an AuthenticateAttribute and the OnActionExecuting event. Those two notions are incompatible. If you are writing a custom authorization attribute you should be probably deriving from AuthorizeAttribute and overriding the AuthorizeCore method for the authentication and the HandleUnauthorizedRequest method for handling the unauthorized case.

    You also have the possibility if you don’t want to use the global HandleErrorAttribute to do the following instead of throwing exceptions:

    filterContext.Result = new ViewResult
    {
        ViewName = "~/Views/Shared/401.cshtml"
    };
    

    Setting a result inside an action attribute will short-circuit the execution of the controller action and directly render the view.

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

Sidebar

Related Questions

I have an ASP.NET MVC 2 application in which I am creating a custom
I have an ASP.NET MVC 2 application which in part allows a user to
I have an asp.net MVC app that i am working on and I wrote
I'm learning about creating custom routes in ASP.NET MVC and have hit a brick
In building a custom ASP.MVC 3 Action Filter, how should I redirect the user
I have made a custom filter that is to fire on every action(request). So
I have a custom validation attribute derived from action filter attribute. Currently the attribute
I have a custom installer action that updates the PATH environment, and creates an
I have a custom login-actionfilter where that I'm trying to upgrade to mvc 2
i m using .NET mvc2 for my application. I want some custom authorization on

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.