i created a new project from visual studio 2019 of type web api
i want my endpoint like that /api/products.json but it not work
<Route("/api/products.json")>
<HttpGet()>
Public Function RetriveData() As ListarRes
Return New ListarRes()
End
when i run the project swagger show perfect but if i test it return error 404
in configuration is enabled MapHttpAttributeRoutes()
the problem is due to “.json” if i chnaged for
<Route("/api/products")>
it works, so how i should create it custom route?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
well it was very easy
asp.net web api – use style
extension == concrete handler
so i created mock handler and it worked
Public Class AppJsonExtension
Implements IHttpHandler
Public ReadOnly Property IsReusable As Boolean Implements IHttpHandler.IsReusable
Get
Return False
End Get
End Property
Public Sub ProcessRequest(context As HttpContext) Implements IHttpHandler.ProcessRequest
End Sub
End Class
and in the web.config added
<system.webServer>
<handlers>
...
<add name="JsonHandler" path="*.json" verb="*" type="TestApp.AppJsonExtension, TestApp" />
</handlers>
</system.webServer>
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0