坚持了几个小时{"Message":"Authentication failed.","StackTrace":null,"ExceptionType":"System.InvalidOperationException"}我试图在我的ASP.Net Webform中调用此WebMethod[WebMethod]public static string GetClients(string searchTerm, int pageIndex){ string query = "[GetClients_Pager]"; SqlCommand cmd = new SqlCommand(query); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@SearchTerm", searchTerm); cmd.Parameters.AddWithValue("@PageIndex", pageIndex); cmd.Parameters.AddWithValue("@PageSize", PageSize); cmd.Parameters.Add("@RecordCount", SqlDbType.Int, 4).Direction = ParameterDirection.Output; return GetData(cmd, pageIndex).GetXml();}从这个jquery.ajaxfunction GetClients(pageIndex) { $.ajax({ type: "POST", url: "ConsultaPedidos.aspx/GetClients", data: '{searchTerm: "' + SearchTerm() + '", pageIndex: ' + pageIndex + '}', contentType: "application/json; charset=utf-8", dataType: "json", success: OnSuccess, failure: function (response) { alert(response.d); }, error: function (response) { alert(response.d); } });}但是我总是会收到这个错误:POST http://localhost:64365/ConsultaPedidos.aspx/GetClients 401(未经授权)奇怪的是,在我开始对用户进行身份验证之前,这种方法一直有效<system.web>... <authentication mode="Forms"> <forms loginUrl="~/Account/Login" timeout="2880" defaultUrl="/Dashboard" /> </authentication> <authorization> <deny users="?" /> </authorization>...</system.web>有任何想法吗?
3 回答
慕哥6287543
TA贡献1831条经验 获得超10个赞
问题解决了
这让我发疯。
在〜/ App_Start / RouteConfig.cs内部更改:
settings.AutoRedirectMode = RedirectMode.Permanent;
至:
settings.AutoRedirectMode = RedirectMode.Off;
(或只是注释行)
另外,如果启用了友善网址,则需要更改
url: "ConsultaPedidos.aspx/GetClients",
至:
url: '<%= ResolveUrl("ConsultaPedidos.aspx/GetClients") %>',
希望这对其他人有帮助
暮色呼如
TA贡献1853条经验 获得超9个赞
内部~/App_Start/RouteConfig.cs变化
settings.AutoRedirectMode = RedirectMode.Permanent;
至
settings.AutoRedirectMode = RedirectMode.Off;
- 3 回答
- 0 关注
- 644 浏览
添加回答
举报
0/150
提交
取消