In ASP.NET MVC (default routing),I’d like to use a URL like this to return a View with a form to edit a customer:
/Customers/Edit/5
I need to make use of CustomerId=5, but I don’t want to permit a customer to change it.Right now I make the id hidden using:
<%= Html.Hidden("CustomerId") %>
This accomplishes what I want,but I’m under the impression that hidden form variables are not secure and can be manipulated by the end user.
So, what’s the best way to allow a customer to edit their information but not their ID?
My solution was to use the Tamper Proofing code from Steven Sanderson’s ASP.NET MVC book. The idea is that you create a hash of any hidden form field you want to tamper proof:
When the form is submitted, Steven’s code then computes another hash of CustomerId and makes certain it equals CustomerIdHash. If it does, then no tampering has occurred. It’s great code, and worth the price of the book.