I am experimenting with WebApi and have created a controller with two methods.
I started with the following method first:
[HttpGet]
[Route("car/{registration}")]
public object GetCarByRegistration(string registration) {
return null;
}
When debugging I put a breakpoint on return null;
tested url http://localhost:51245/api/car/yw25jdk
which work fine, visual studio stopped at my breakpoint and the registration
variable was the same value in the url.
But when I added the following method:
[HttpGet]
[Route("car/{serial}")]
public object GetCarBySerial(string serial) {
return null;
}
The first url stopped working and I started to get 500 - Internal Server Error
. If I take the second method out then the first method works again.
I cannot understand why the second method breaks the first one.
Can someone explain this to me please?
Well thats because ASP does not know which method to use when you go to the url http://localhost:51245/api/car/yw25jdk
since both methods say they expect a string as their parameter.
How should ASP know the difference between /car/{registration}
and /car/{serial]
, since both of them are string?
You should change the Route of on of them, to get it working
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With