Click here to Skip to main content
15,890,506 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
for editing a data in views we should specify an "Id" to submit to out controller. but imagine that user manually change "Id" value. for example Id=10 change to Id=15 (by some tools in browser like Inspect). in this case EF update data with Id value 15 and trick our application. what is the best solution to overcome this issue?

please help for this issue and mentioned solution. thanks

What I have tried:

My Solution: in each domain class create a property named "UniqueId" as string type and when we add data to database, this property must be valued with GUID besides "Id" value. now when we send view to user UI we must send both property "Id" & "UniqueId" as hidden, then when client post data to controller for update, our logic section shall check "Id" & "UniqueId" both together and if any nonconformity existed, we can throw exception.
Posted
Updated 11-Apr-22 16:39pm

1 solution

The user should never see the ID value, let alone be able to change it. If needed, you can include the ID value in a Hidden element in your page, but never let the user change it.

You don't need the extra id value of a GUID, but using a GUID as the primary key in a table is preferred over using an integer.
 
Share this answer
 
Comments
Peter_in_2780 12-Apr-22 3:28am    
I think the OP's point is that hidden elements can be manipulated using browser dev tools.
Dave Kreskowiak 12-Apr-22 8:00am    
Yeah, I wasn't entirely sure what he was talking about, so that's why I suggested using the GUID as the PK.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900