c# – Pass encrypted data by URL in ASP.NET MVC

Question:

I need to pass a link, but I didn't want to leave it too exposed, I would like to know how to Encrypt at least the object id. I created a class for Encryption, but it generates "/" and this puts it as a route in MVC.

Answer:

Keep using your encryption on the parameters, but to avoid problems with characters not allowed in the Url, before sending the string, use the HttpContext.Current.Server.UrlEncode() method.

When reading the string again, use the HttpContext.Current.Server.UrlDecode() method.

When outside of an ASP.NET application, if you are using Framework 4.5 onwards, it is recommended to use the WebUtility class to access the UrlEncode and UrlDecode methods.

Scroll to Top