asp.net mvc 의 form 태그를 자동적으로 AntiForgeryToken 사용하도록 하기 위해 핼퍼를 만든 부분임
// BeginForm replacement for HtmlHelper
public static MvcForm BeginSecureForm
(this HtmlHelper htmlHelper, string actionName, string controllerName)
{
var form = htmlHelper.BeginForm(actionName, controllerName);
htmlHelper.ViewContext.Writer.Write(htmlHelper.AntiForgeryToken().ToHtmlString());
return form;
}
// BeginForm replacement for AjaxHelper
public static MvcForm BeginSecureForm(this AjaxHelper ajaxHelper, AjaxOptions ajaxOptions)
{
var form = ajaxHelper.BeginForm(ajaxOptions);
ajaxHelper.ViewContext.Writer.Write(AntiForgery.GetHtml());
return form;
}
사용법
// View
@using (Html.BeginSecureForm("AddUser", "Home"))
{
@Html.TextBox("userName")
<button type="submit">Save</button>
}
https://www.codeproject.com/Tips/1170283/Validate-Anti-Forgery-in-ASP-NET-MVC-The-Automated
출처: http://aspdotnet.tistory.com/1790 [심재운 블로그]
첫댓글 오잉 신선하네요.. 엄청 새로운건 아니지만..
팀원들한테 포스트 할때 빠트리지 말라고 항상 말하는데 이게...
정말 결제처럼 중요한데가 아니면 자주빠트리더라고요.. 차라 form 함수를 항상쓰는걸로 통일하면 이런
문제는 해결되겠어요
네 ㅎㅎ 자주 빠지고 뷰에 반복 작업이니 많이 애용해 주세용 ㅎ