I am using this for Anti Forgery in my asp.net 4.5 web form application.
<form id="form1" runat="server" class="formCont" method="post">
<%= System.Web.Helpers.AntiForgery.GetHtml() %>
using Namespace
using System.Web.Helpers;
and on page load
AntiForgery.Validate();
it's working fine.
Now I have created may asp generic handler
for ajax call from javascript. Now the issue is how can I validate the same in my generic handler.
I have tried this in my ajax call
data: { "__RequestVerificationToken": $("input[name=__RequestVerificationToken]").val() },
and in handler trying this AntiForgery.Validate();
but I am getting the exception
An exception of type 'System.Web.Mvc.HttpAntiForgeryException' occurred in System.Web.WebPages.dll but was not handled in user code
Additional information: The required anti-forgery form field "__RequestVerificationToken" is not present.
I have checked in and I am getting the values in context.Request["__RequestVerificationToken"]
how can I over come this issue.
I got the solution
It was looking in context.Request.Forms
collection so I make a small change as below
type: "POST",
and bingo it worked.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.