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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T10:27:41+00:00 2026-05-12T10:27:41+00:00

I am trying to list all the controllers and their actions with specific attributes

  • 0

I am trying to list all the controllers and their actions with specific attributes to create a dynamic google sitemap. So that I can “mark” certain actions with an attribute so they show up in the sitemap.

Here I found out how to get all the controllers. But I am not sure how to get all their Actions with a particular attribute. I tried GetMethods and then use GetCustomAttributes but I am not sure if that’s the right way to do it. It felt a little over complicated.

Once I get the controllers and their actions I was going to use the technique explained here to get the urls. As you may notice Eric Duncan talks about what I am trying to accomplish in that question.

Thanks in advance.

  • 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-12T10:27:41+00:00Added an answer on May 12, 2026 at 10:27 am

    I use some code in my unit tests to verify that certain actions are decorated with attributes. It uses reflection with some enumerable extension method goodness. I think you could adapt this. Note, if you only care about whether it exists or not, you could use Count() on the enumeration rather than getting the actual attribute. This way allows you some flexibility in using attribute properties to customize the behavior. Using the inheritance tree would allow you to decorate an entire controller.

     var methods= controller.GetType()
                            .GetMethods( BindingFlags.Public | BindingFlags.Instance )
     foreach (var info in methods)
     {
         if (info.ReturnType  == typeof(ActionResult))
         {
            var attribute = info.GetCustomAttributes( typeof( SiteMapAttribute ), true )
                                .Cast<SiteMapAttribute>()
                                .FirstOrDefault();
    
            if (attribute != null && !attribute.Exclude.Contains( info.Name ))
            {
                ...
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to display a list of all files found in the selected
I'm trying to make a horizontal list of links with <ul> wherein all <a>
Trying to create a list to return some JSON data to a view. Following
I'm trying to find a way to list the (static) dependency requirements of a
I'm trying to bind a list of custom objects to a WPF Image like
I'm trying to combine a list of functions like so. I have this: Func<int,
I am trying to sort a list using delegates but I am getting a
I am trying to build a dropdown list for a winform interop, and I
I'm trying to use a generic List as a property on a ServicedComponent class...
Basically I am trying to retrieve a list of stored procedure parameters using Linq

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.