亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用jQuery AJAX“ 401(未經授權)”的ASP.NET調用WebMethod

使用jQuery AJAX“ 401(未經授權)”的ASP.NET調用WebMethod

呼啦一陣風 2019-10-18 09:56:44
堅持了幾個小時{"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") %>',

希望這對其他人有幫助


查看完整回答
反對 回復 2019-10-18
?
暮色呼如

TA貢獻1853條經驗 獲得超9個贊

內部~/App_Start/RouteConfig.cs變化


settings.AutoRedirectMode = RedirectMode.Permanent;


settings.AutoRedirectMode = RedirectMode.Off;


查看完整回答
反對 回復 2019-10-18
  • 3 回答
  • 0 關注
  • 697 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號