How to Prevent Parameter Tampering

lesponce 176 Reputation points
2021-12-08T19:25:59.267+00:00

How can I prevent parameter tampering in my code below?

    var MyTest = await _context.MyTable.Where(x => x.ID == EmployeeID).ToListAsync();
Developer technologies ASP.NET ASP.NET Core
Developer technologies C#
{count} vote

Accepted answer
  1. Karen Payne MVP 35,586 Reputation points Volunteer Moderator
    2021-12-09T02:19:53.967+00:00

    You can create a class like the following

    public class Integer  
    {  
        public int Id { get; init; }  
        public Integer(int id)  
        {  
            Id = id;  
        }  
    }  
    

    Pass it to a method which can use it but not alter Id property

    156068-immutable.png


1 additional answer

Sort by: Most helpful
  1. Tom Phillips 17,771 Reputation points
    2021-12-08T21:41:21.723+00:00

    This is a .Net question.

    .Net support is on stackoverflow. I suggest you post your question here:

    https://stackoverflow.com/questions/43564427/how-to-prevent-the-visitor-from-tampering-with-the-id-field-in-post-action

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.