security - How to extend or override BeginForm to include a AntiForgeryToken field -
i reading article (http://weblogs.asp.net/dixin/archive/2010/05/22/anti-forgery-request-recipes-for-asp-net-mvc-and-ajax.aspx) how prevent csrf attacks. seems solution create tag inside each form.
<%: this.html.antiforgerytoken(constants.antiforgerytokensalt)%>
however, don't want copy , paste code inside of each form. extend or override beginform create beginsecureform automatically adds antiforgerytoken. not sure how add content inbetween of beginform , endform.
any ideas?
you should use instead, place token @ right place, after form :
public static mvcform beginantiforgeryform(this htmlhelper htmlhelper) { var mvcform = htmlhelper.beginform(); htmlhelper.viewcontext.writer.write(htmlhelper.antiforgerytoken().tohtmlstring()); return mvcform; }
Comments
Post a Comment