Web API Routes to support both GUID and integer IDs

后端 未结 1 339
既然无缘
既然无缘 2021-02-05 05:34

How can I support GET routes for both GUID and integer? I realize GUIDs are not ideal, but it is what it is for now. I\'m wanting to add support for integers to mak

相关标签:
1条回答
  • 2021-02-05 05:56

    Thank you to @SirwanAfifi! I had come across the Attribute Routing in ASP.NET article referred to in the SO question you mentioned, but apparently I didn't see the need for route attribute constraints at the time.

    For me, it was using [Route("{id:guid}")] and [Route("{key:int}")] on my controller methods that did the trick. I also commented out the Http routes related to {id} and {key} in my WebApiConfig to verify that the attributes in the controller are responsible for doing the routing.

    0 讨论(0)
提交回复
热议问题