Paul Fryer
Paul Fryer

Reputation: 9527

Where is the RouteOrder property on the Route attribute?

According the asp.net documentation there is a property called RouteOrder on the RouteAttribute. However I can't find that in code. I can find Order, but not RouteOrder. Should I assume these are the same?

enter image description here

Upvotes: 4

Views: 378

Answers (1)

Nate Barbettini
Nate Barbettini

Reputation: 53610

Yes, they are the same. I was following the same article and I ran into this problem (RouteOrder does not exist in System.Web.Http.RouteAttribute).

I did a quick test in my Web API 2 application to verify:

[Route("{name}")] // unconstrained parameter
[HttpPost]
public string Test(string data) {
    return data;
}

[Route("preview")] // literal
[HttpPost]
public string Preview(string data) {
    return data;
}

When I hit api/preview with Fiddler, Preview() is hit since literal segments are considered before parameter segments. If I change it to give less importance to the literal action:

[Route("preview"), Order = 1] // literal
[HttpPost]
public string Preview(string data) {
    return data;
}

And hit api/preview again, Test() is hit, in line with the documented behavior of RouteOrder. I have no idea why it was renamed, but it's the same thing!

Upvotes: 1

Related Questions