webforms - preventing cross-site request forgery (csrf) attacks in asp.net web forms -
i have created asp.net web form application using visual studio 2013 , using dot net frame work 4.5, , want make sure site secure cross-site request forgery (csrf), have found many articles talking how feature implemented on mvc apps, few talking web forms, on this stackoverflow question 1 comment stating
"this old question, latest visual studio 2012 asp.net template web forms includes anti-csrf code baked master page. if don't have templates, here's code generates:..."
but master page not contain code has mentioned in answer, can 1 please me? implemented? if not, please advise best way it?
you try following. in web-form add:
<%= system.web.helpers.antiforgery.gethtml() %>
this add hidden field , cookie. if fill out form data , post server need simple check:
protected void page_load(object sender, eventargs e) { if (ispostback) antiforgery.validate(); }
antiforgery.validate();
throws exception if anti xsfr check fails.
Comments
Post a Comment