0

I need to add dot (.) in path parameter and it turns out that dot will only work if we append a / slash at the end of that parameter.

For example: /api/path.param/?q=123 this will work

However: /api/path.param?q=123 wont work without the trailing slash

I was hoping to programmatically add the slash / if the query parameter is q=123.

How can this be done in MVC 4?

rfa
  • 13
  • 3
  • You can use a dot in the path without adding a `\`: https://stackoverflow.com/questions/11728846/dots-in-url-causes-404-with-asp-net-mvc-and-iis – Johan Donne Feb 05 '22 at 06:44

1 Answers1

0

If the /api/path.param is always the same you could use (the hack-y method):

variable_name = variable_name.Substring(0, 15) + "/" + variable_name.Substring(15);

If it isn't always the same you could do (the more dynamic method):

int index = variable_name.IndexOf("?q=");
variable_name = variable_name.Substring(0, index) + "/" + variable_name.Substring(index);
s_ofia
  • 117
  • 1
  • 10
  • where is this added, controller, route config? can you show that – rfa Feb 05 '22 at 15:07
  • Well I need more context to the way that your script works, this code would go after the `/api/path.param?q=123` is formed but before it is used. – s_ofia Feb 05 '22 at 22:22
  • assuming that to be the controller, it is not even reaching controller – rfa Feb 07 '22 at 01:51
  • This is a pathstring submitted to the app, the fail occurs before code that responds to the pathstring even is invoked. This Answer needs clarity on where the pathstring update could occur. – StackOverflowUser Feb 08 '23 at 07:21