0
我在我的asp.net 4.5網頁表單應用程序中使用了這種防僞技術。AntiForgery Asp.net網絡表單
<form id="form1" runat="server" class="formCont" method="post">
<%= System.Web.Helpers.AntiForgery.GetHtml() %>
使用命名空間
using System.Web.Helpers;
,並在頁面加載
AntiForgery.Validate();
它的正常工作。
現在我創建了可能asp generic handler
來自javascript的ajax調用。現在的問題是我如何驗證我的通用處理程序中的相同。
我在Ajax調用嘗試這種
data: { "__RequestVerificationToken": $("input[name=__RequestVerificationToken]").val() },
,並在處理程序嘗試這種AntiForgery.Validate();
但我得到異常
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.
我在檢查,我在context.Request["__RequestVerificationToken"]
得到的值
我怎麼能過來這個問題。
你用什麼格式發佈數據? JSON? '應用程序/ x-WWW的形式urlencoded'? – mason
@mason它的默認值我沒有指定任何。 –
然後使用瀏覽器的網絡工具查看AJAX請求。比較一下,正常的職位看起來像。指出不同。 – mason