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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:08:52+00:00 2026-06-15T20:08:52+00:00

I’m trying to setup an Area Route in my ASP.NET MVC application. I’m also

  • 0

I’m trying to setup an Area Route in my ASP.NET MVC application.

I’m also using the nuget package AttributeRouting, not the normal MVC register area routes thingy.

From my understanding, area routes look like this : /area/controller/method

What I’m trying to do is :- /api/search/index

which means:

  • Area => Api
  • Controller => SearchController
  • ActionMethod => Index

.

[RouteArea("Api")]
public class SearchController : Controller
{
    [POST("Index")]
    public JsonResult Index(IndexInputModel indexInputModel) { .. }
}

But that doesn’t create that route. This is what it creates: /api/index
The search controller is missing.

I’ve had a look the docs and noticed the RoutePrefix so I tried this..

[RouteArea("Api")]
[RoutePrefix("Search")]
public class SearchController : Controller
{
    [POST("Index")]
    public JsonResult Index(IndexInputModel indexInputModel) { .. }
}

and that actually creates the route /api/search/index.

But why do i need to put the RoutePrefix in there? Shouldn’t it be smart enough to already figure out that this is a SearchController and create the 3-segment route?

  • 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-15T20:08:53+00:00Added an answer on June 15, 2026 at 8:08 pm

    You don’t need to put a RoutePrefix anywhere. It’s just there as a refactoring/DRY aid. Consider:

    [RouteArea("Api")]
    public class SearchController : Controller 
    {
        [POST("Search/Index")]
        public ActionResult Index() { }
    }
    

    If you had a number of actions, maybe you want them all with the “Search” prefix, so you’d do:

    [RouteArea("Api")]
    [RoutePrefix("Search")]
    public class SearchController : Controller 
    {
        [POST("Index")]
        public ActionResult Index() { }
    
        // Other actions to prefix....
    }
    

    Shouldn’t it be smart enough?

    Not to be cheeky, but no. AR was never intended to read all your code for you and magically generate routes. It was intended to keep your URLs top of mind, and to do that you should see your URLs. Not that this is the best or only way of doing things, just that was my intent from the get.

    The real reason why it isn’t smart enough is that the concept of “Area” has nothing to do with URL. An area is a logical unit. You could expose that logical unit without any route prefix (so it would be hanging off ~/) or you could expose it off “This/Is/A/Prefix”.

    However, if you want it to be smart enough…. I just released v3.4, which will let you do this (if you want to; don’t have to):

    namespace Krome.Web.Areas.Api
    {
        [RouteArea]
        [RoutePrefix]
        public class SearchController : Controller 
        {
            [POST]
            public ActionResult Index() { }
        }
    }
    

    This will yield the following route: ~/Api/Search/Index. The area comes from the last section of the controller’s namespace; the route prefix comes from the controller name; and the rest of the url comes from the action name.

    One more thing

    If you want to get out a route area url and route prefix rat’s nest for individual actions in a controller, do this:

    [RouteArea("Api")]
    [RoutePrefix("Search")]
    public class SearchController : Controller 
    {
        [POST("Index")]
        public ActionResult Index() { }
    
        [GET("Something")] // yields ~/Api/Search/Something
        [GET("NoPrefix", IgnoreRoutePrefix = true)] // yields ~/Api/NoPrefix
        [GET("NoAreaUrl", IgnoreAreaUrl = true)] // yields ~/Search/NoAreaUrl
        [GET("Absolutely-Pure", IsAbsoluteUrl = true)] // yields ~/Absolutely-Pure 
        public ActionResult Something() {}
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am reading a book about Javascript and jQuery and using one of the
I am trying to render a haml file in a javascript response like so:
I am using the SimpleRSS gem to parse a WordPress RSS feed. The only

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.