Reputation: 39374
On ASP.NET MVC 5.1 I have an action which receives an encrypted string, for example:
Nf7JnWp/QXfA9MNd52RxKpWg=
But I get a 404 error because of the slash inside this string ...
I tried to encode the string with HttpUtility.UrlEncode and WebUtility.UrlEncode;
But I keep having the same problems. Does anyone knows how to solve this?
Thank You,
Miguel
Upvotes: 4
Views: 914
Reputation: 23937
You can build a workaround for this by defining a custom route. Now I do not know how you named your controller or your action, so I'll use generic names.
routes.MapRoute(
"SpecialControllerName",
"CustomName/{*id}",
new { controller = "CustomName", action = "CustomAction", id = UrlParameter.Optional }
);
public ActionResult Name(string id)
{
//logic goes here
}
So what we did here, is take the action out of the equation. Now if you call http://yourdomain.com/CustomName/Nf7JnWp/QXfA9MNd52RxKpWg=
it will call the Action method CustomName
in the Controller CustomNameController
.
Please note, that the asp.net Framework takes the first route in your route config, which matches its patterns. If you have your Defaultroute and place your new custom route below it, it will fail. Placing the Custom route above it, will work
Similar questions on SO:
Upvotes: 2