Preventing over-posting

We can use the BindProperty attribute to decorate either a model or a specific controller action.

You can either have a blacklist or a whitelist approach in using the BindProperty attribute. A whitelist approach proves to be safer and simpler because you simply target those properties you need to bind. 

As another form of mitigation, we can just create a view model with just the properties that are needed for a user to fill in, and in that way prevent any binding targeted directly at your full model.

The usage of BlogCommentViewModel will be able to prevent over-posting:

public class BlogCommentViewModel {
public string UserName { get; set; }
public string Comment { get; set; }
}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
52.15.55.18