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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:21:31+00:00 2026-06-18T00:21:31+00:00

I want to intercept every request coming into my MVC app after the ControllerName

  • 0

I want to intercept every request coming into my MVC app after the ControllerName and Action have been resolved, but before the request is serviced, i.e. before it reaches the appropriate action.

I have thought of two ways of doing this:

1) I could write an HttpModule to intercept every incoming HttpRequest, read the HttpContext.Request.AbsoluteUrl (or some such) property, then assume that the route I have configured will never be changed (and that is the assumption I want to avoid or I would have gone this way), and infer the names of the controller and action that are being invoked.

However, I am looking for a more reliable way. Hence (2) below.

2) I assume that MVC already does this for me at one time or another before instantiating the right controller. I want to know where it does that so I may be able to re-use its work. At which point may I get this information, intercept the request and do something about it before it reaches the action?

  • 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-18T00:21:33+00:00Added an answer on June 18, 2026 at 12:21 am

    You could create a global action filter where you will have access to the controller and action:

    public class MyGlobalActionFilter : ActionFilterAttribute
    {
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            string controller = filterContext.RouteData.GetRequiredString("controller");
            string action = filterContext.RouteData.GetRequiredString("action");
            // do something with those variables ...
        }
    }
    

    The OnActionExecuting method will be invoked before every controller action is ran and you will be able to retrieve the information you are looking for from the RouteData.

    And then simply register your global action filter in your Application_Start:

    GlobalFilters.Filters.Add(new MyGlobalActionFilter());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to intercept long press on UITextview, but don't want to disable the
I have an app that makes a HTTP GET request to a particular URL
I want to intercept all route changes with Sammy to first check if there
I just want to intercept raw data (hex)--headers and all--sent to a port, and
I'm starting a Stack Exchange site and I want to be able to intercept
I want to interrupt a thread after a fixed amount of time. Someone else
I want to write a MobileSubstrate ( http://www.iphonedevwiki.net/index.php/MobileSubstrate ) addon that takes every HTTP
I apologize if this question is vague, but I want to build a drop
I have inherited a conventional three tier web app with ASP.net 2.0 for the
I am working on a web app using JSF w/Seam. I want to be

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.