I'm looking for case sensitive routing in ASP.NET Core 2.2 application.
For example:
[HttpGet("/yes}")]
public IActionResult Test()
domain.com/yes and domain.com/YES going to same action. But I want this to be completely case sensitive.
https://www.visualupload.com/u/2CU
https://www.visualupload.com/U/2CU (u is uppercase and both working.)
How can I fix this?
As other posters have mentioned I would strongly discourage this operation, as it can be a nightmare for a number of reasons. However, it would be possible to do this, using the default routes.
public class MyController : Controller
{
public IActionResult MyAction(string id){ }
}
The standard routing process would pass the request of /My/MyAction/TeST to your MyAction method.
You could then have conditional logic to do your case-sensitive stuff inside of the MyAction method.
Again, this isn't a recommended approach, but it is one way you could accomplish the goal.
Edited: Inside of this you might have something similar to this
switch(id)
{
case "lowercase":
return MyLowercaseAction();
case "MiXeDcAsE":
return MyMixedCaseAction();
//etc.
}
You would then have individual methods that returned action results for the various scenarios. Or whatever else you needed to do. The key is that you will receive the information and need to take the case-sensitive action on your own.
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