Razor Page encrypt id property

118 Views Asked by At

Working with razor pages\Core 7.0 for the 1st time and my question is

Does the Core have the ability to have an attribute on the Id property that would encrypt on render and decrypt it on post back?

For example my Input Model

[BindProperty]
public InputModel Input { get; set; }

public class InputModel
{
[Encrpyt(Salt= "123ABC"]
public string UserId { get; set; }

[Required]
[DataType(DataType.PhoneNumber)]
public string Phone { get; set; }

[Required]
[Display(Name = "First Name")]
public string FirstName { get; set; }

[Required]
[Display(Name = "Last Name")]
public string LastName { get; set; }

}

I could use a tag helper like this <input asp-for="Input.UserId" type="hidden" />

During the binding on a Post the Input Model would decrypt the id back to a string. Is there an alternative?

The link I am reading is here: https://learn.microsoft.com/en-us/aspnet/core/data/ef-rp/crud?view=aspnetcore-7.0#update-the-edit-page The example leaves the PK exposed and a user could simply change the hidden value and they updated some other record.

0

There are 0 best solutions below