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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T11:19:00+00:00 2026-06-05T11:19:00+00:00

The web api seems to be only suited for the standard use-cases. But I

  • 0

The web api seems to be only suited for the standard use-cases.
But I want to do more complex routing but can’t find documentation for complex routing.
If I have more controller, the routings gets more and more complicated.

Can i define several optional parameters with dependencies?
Like this:

/api/document/{par1}/{par2}

par1 & par2 should be optional but par2 should be only matched if par1 is present.

And are recursive parameters possible?

/api/documents/characteristics/{round/green/red-dots}
/api/documents/characteristics/{square/yellow}
/api/documents/characteristics/{square/yellow/flat}
/api/documents/characteristics/{square/yellow/flat/...}

Is there a detailed documentation for the web api routing? The microsoft tutorial is too basic…
I need more information about the routing.

I have two controllers and some trouble because two routings are quite similar, so the wrong route is taken. I can use [Action]-Attribute as a workaround, but this feels not right… I also have to consider the order of the routes. This is logical but is nowhere mentioned.
Is the web api only for simple rest api’s?


Edit:
I tried this:

routes.MapHttpRoute(
           name: "DefaultApi",
            routeTemplate: "api/{mandant}/documents/{id}",
            defaults: new { controller = "documents", id = RouteParameter.Optional }
            );

//routes.MapHttpRoute(
//    name: "DefaultApiWithAction",
//    routeTemplate: "api/{mandant}/documents/{id}/{action}",
//    defaults: new { controller = "documents" }
//    );

I have two methods:

[AcceptVerbs("get")]
public HttpResponseMessage Get(int id)

[ActionName("file")]
[AcceptVerbs("get")]
public HttpResponseMessage filedownload(int id)

Now I have the problem, the file-action is triggered even if I comment out the second route and the normal get specific document method is not triggered because multiple actions… I tried the [NoAction] attribute but this is not working…
But why will the file-method be triggered if there is no action in the route-template? (Or if the second route is active, why will the normal get-document method not be triggered if there is no action in the url….)
I my current workaround is to set a default-action for all other methods, but this is not a good solution.

  • 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-05T11:19:01+00:00Added an answer on June 5, 2026 at 11:19 am

    You can use routing constraints to set conditions on the routing in global.asax like:

    routes.MapRoute(
        "ApiRoute",
        "api/document/{par1}/{par2}",
        new {controller="Document", action="SomeMethod"},
        new {par1 = @"\d+" }
     );
    

    In the last parameter you can specify regular expression that has to be matched for specified parameter for the route to be used. In the example above par1 is used for digits only, but you can use any regular expression, like:

    routes.MapRoute(
        "ApiRoute",
        "api/document/{par1}/{par2}",
        new {controller="Document", action="SomeMethod"},
        new {par1 = @"(value1|value2|value3)" }
     );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I create a new ASP.NET Web API project. I then use nuget to pull
I'm trying to use the Picasa Web Uploader API to upload galleries of photos
I want to try to use the Yahoo Fantasy Sports API for my fantasy
I need to make a web application and I want to use MVC. However,
Microsoft is encouraging developers to use asp.net web api for creating Restful services. I
I implemented the exception filter like here: http://www.asp.net/web-api/overview/web-api-routing-and-actions/exception-handling And registered it globally, like microsoft
I'm calling a web API exposed by TheyWorkForYou (TWFI). http://www.theyworkforyou.com/api/ I'm using the Python
New ASP.NET Web API HttpClient has been giving me some strange results. Here is
My small Web API project (hosted via SelfHostHttpServer ) has a few dependencies I
I'm writing a Web API service and trying to return a (400) Bad Request

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.