Reputation: 12729
I have a controller with a method that has a variable passed in the route - the Controller:
[Route("cont/{MyParameter}")]
public ActionResult Index(string MyParameter)
{
...
}
When I pass a value (abcdef) in the URL like this it's fine:
http://localhost/my-website/cont/abcdef
But when I pass one with encoded slashes - it fails - as if the slashes aren't encoded - e.g.:
http://localhost/my-website/cont/abc%2fdef
I get a "The Resource cannot be found" in IIS - with a requested URL displayed in the body of:
Requested URL
http://localhost:80/f-website/cont/abc/def
It appears to have added slashes - even though they were encoded.
The address bar still shows the original URL with %2f in however.
How can I pass / in as a parameter? I thought URL Encoding was the solution here but it apparently is having no effect.
I can find nothing on Google about this specific issue.
Upvotes: 5
Views: 3641
Reputation: 3267
Best solution I found was using a wildcard:
[HttpGet]
[Route("my-action-url/{*parameter}")]
public IActionResult MyAction(string parameter)
{
// Some code here
}
Upvotes: 2