Attributes ASP.NET MVC5 -


there multiple tags generated automatically in asp.net mvc5 project such

  • httppost
  • actionname("delete")
  • validateantiforgerytoken

    1. is httppost / validateantiforgerytoken pratice or mandatory?
    2. when declaring function httppost attribute happening?

thanks

when declaring function httppost attribute doing? posting web server or returning data view?

neither. when declare action method attribute:

[httppost] public actionresult somemethod(somemodel model) {     // code } 

what you're doing indicating requests should route method if request uses post http verb. users can't attempt invoke action issuing get request, example.

whether or not httppost "good practice" entirely subjective. use when want restrict http verb can invoke method, don't use when don't want make restriction.

validateantiforgerytoken attribute use when want enact particular restriction. works in conjunction the @html.antiforgerytoken form element helper. purpose ensure requests validate token received users have received token, helps prevent request forgeries.

basically, if place @html.antiforgerytoken in view's form create unique value specific instance of form. form post action method validates token first check token 1 that's been issued server before processing request. way users can't capture form post , replay many times, because server-issued token need different each time.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -