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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T08:31:54+00:00 2026-05-14T08:31:54+00:00

How can I get the controller action (method) and controller type that will be

  • 0

How can I get the controller action (method) and controller type that will be called, given the System.Web.Routing.RouteData?

My scenario is this – I want to be able to do perform certain actions (or not) in the OnActionExecuting method for an action.

However, I will often want to know not the current action, but the “root” action being called; by this I mean I may have a view called “Login”, which is my login page. This view may include
another partial view “LeftNav”. When OnActionExecuting is called for LeftNav, I want to be able to determine that it is really being called for the “root” aciton of Login.

I realise that by calling RouteTable.Routes.GetRouteData(actionExecutingContext.HttpContext), I can get the route for the “root” request, but how to turn this into
method and type info?

The only solution I have so far, is something like:

 var routeData = RouteTable.Routes.GetRouteData(actionExecutingContext.HttpContext)
 var routeController = (string)routeData.Values["controller"]; 
 var routeAction = (string)routeData.Values["action"];

The problem with this is that “routeController” is the controller name with the “Controller” suffix removed, and is not fully qualified; ie it is “Login”, rather than “MyCode.Website.LoginController”.

I would far rather get an actual Type and MethodInfo if possible, or at least a fully qualified type name.

Any thoughts, or alternative approaches?

[EDIT – this is ASP.Net MVC 1.0]

  • 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-14T08:31:54+00:00Added an answer on May 14, 2026 at 8:31 am
      protected override void OnActionExecuting(ActionExecutingContext filterContext)
      {
         var type1 = filterContext.Controller.GetType();
         var type2 = filterContext.ActionDescriptor
                        .ControllerDescriptor.ControllerType;
      }
    

    OK, sorry, I missed the “root” part.

    Then, another way, you can save controller type to thread storage. Pseudocode:

      protected override void OnActionExecuting(ActionExecutingContext filterContext)
      {
         if (!Thread.LocalStorage.Contains("root_controller"))
            Thread.LocalStorage["root_controller"] = 
                filterContext.ActionDescriptor
                        .ControllerDescriptor.ControllerType;
      }
    

    Just an idea. I’m sure thread local storage is available in C#. The key idea here is that you save it only for first request, thus it’s always root controller.

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

Sidebar

Related Questions

When I type the URL like ../Search/Recipes/Deserts/Pie, I can get redirected to that page
How can I get the controller name of a relative Url, using the routes
How can I get the controller name out of the object if I don't
00:02.0 VGA compatible controller: InnoTek Systemberatung GmbH VirtualBox Graphics Adapter how can i get
So lets suppose we have an action in a controller that looks a bit
I have a controller action that is receiving a complex object via JSON. The
I am trying to achieve a JQuery AJAX call to a controller action method
In my Action, I have an error of type System.MissingMethodException when I use TryUpdateModel.
I have built and MVC3 application with a controller (Picture) and an action method
In ASP.NET MVC controller methods can be decorated to accept on specific HTTP Methods(Get,

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.