In my ASP.NET MVC app, I want to encrypt the route data and NOT QueryString, in other word:
I\'m using the ASP.NET MVC default route pattern :
rou
You can use a custom model binder for this parameter
// /Controller/Example/0000000A
public ActionResult Example([ModelBinder(typeof(EncryptDataBinder))]int id)
{
return View(id);
}
The model binder
public class EncryptDataBinder : DefaultModelBinder
{
public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
{
if (bindingContext.ModelType == typeof(int))
{
var valueProviderResult = bindingContext.ValueProvider.GetValue(bindingContext.ModelName);
if (valueProviderResult != null)
{
// Use your own logic here
bytes = ConvertUtilities.ToBytesFromHexa((string)valueProviderResult.RawValue);
return BitConverter.ToInt32(bytes, 0);
}
}
return base.BindModel(controllerContext, bindingContext);
}
}