验证调用使用$阿贾克斯Web方法时失败的错误 [英] Authentication failed error when calling web method using $.ajax
问题描述
当我做一个JQuery的电话,我得到验证失败响应:
When I make a JQuery call, I get an Authentication failed response:
{
Message: "Authentication failed.",
StackTrace: null,
ExceptionType: "System.InvalidOperationException"
}
jQuery的电话:
jQuery call:
$(document).ready(function () {
//Handle the change event for the drop down list
$("#ddRegions").change(function () {
//create the ajax request
$.ajax({
type: "POST", //HTTP method
url: '<%= ResolveUrl("WebForm2.aspx/getLocations")%>', //page/method name
data: "{}", //json to represent argument
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) { //handle the callback to handle response
//request was successful. so Retrieve the values in the response.
alert(msg.toSource());
}
});
});
});
Web方法:
The web method:
public static string getLocations() {
System.Diagnostics.Debug.WriteLine("Getting Locations.");
return "{region:auckland, city:auckland}";
}
我添加以下到我的web.config:
I added the following to my web.config:
<authorization>
<allow users="*" />
</authorization>
<authentication mode="None" />
和我尝试设置 AutoRedirectMode
到<在 RouteConfig.cs
关闭>。这将停止错误,但仍然Web方法永远不会被调用。有什么建议?
And I tried setting the AutoRedirectMode
to Off
in RouteConfig.cs
. This stops the error, but still the web method never gets called. Any suggestions?
推荐答案
在App_Start / RouteConfig.cs设置AutoDirectMode为关闭已解决
Resolved by setting AutoDirectMode to Off in App_Start/RouteConfig.cs
settings.AutoRedirectMode = RedirectMode.Off;
和添加一个ScriptManager到具有设置为真的的EnablePageMethods aspx页面:
and adding a ScriptManager to the aspx page that has an EnablePageMethods set to 'true':
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="True">
</asp:ScriptManager>
这篇关于验证调用使用$阿贾克斯Web方法时失败的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!