I have an ApiController and I want to use email addresses as an ID parameter for requests:
// GET api/employees/email@address.com public CompactEmployee Get(string id) { var email = id; return GetEmployeeByEmail(email); }
However, I cannot get this to work (returns 404 ):
http://localhost:1080/api/employees/employee@company.com
The following works:
http://localhost:1080/api/employees/employee@companyhttp://localhost:1080/api/employees/employee@company.http://localhost:1080/api/employees?id=employee@company.com
I set relaxedUrlToFileSystemMapping="true" to my web.config as detailed by Phil Haack .
I would really like the full email address for the job, but at any moment followed by some other character, the request returns 404. Any help would be greatly appreciated!
Decision
Due to the lack of other options, I headed in the direction suggested by Maggie and used the answer from this question to create a rewrite rule to automatically add trailing slash when I need to send an email address.
<system.webServer> .... <rewrite> <rules> <rule name="Add trailing slash" stopProcessing="true"> <match url="^(api/employees/.*\.[az]{2,4})$" /> <action type="Rewrite" url="{R:1}/" /> </rule> </rules> </rewrite> </system.webServer>
asp.net-mvc asp.net-web-api asp.net-mvc-routing
Jonathan Freeland Nov 08 2018-12-12T00: 00Z
source share