如何使用jquery修复ASP.NET中的401(未授权) [英] How to fix 401 (unauthorized) in ASP.NET with jquery

查看:66
本文介绍了如何使用jquery修复ASP.NET中的401(未授权)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



i得到jquery-1.11.3.js:9664 POST http:// localhost:1971 / MyHome.aspx / switchToOtheruser 401(Unauthorized)错误,如何修复此错误,请急,请帮帮我,提前谢谢



我尝试过的事情:



Hi,
i am getting jquery-1.11.3.js:9664 POST http://localhost:1971/MyHome.aspx/switchToOtheruser 401 (Unauthorized) error,how to fix this error ,its urgent ,please help me out,thanks in advance

What I have tried:

$('#btnSwitchLogin').on('click', function (evt) {
       var query = '~' + window.location.pathname + window.location.search;
       var dto = { url: query };
       $.ajax({
           type: "POST",
           url: MyHome.aspx / switchToOtheruser,
           data: JSON.stringify(dto),
           contentType: "application/json; charset=utf-8",
           dataType: "json",
           dto: {
               UserID: $('#userList').val()
           }
       });
   });





和我的C#代码:





and my C# code:

public static void switchToOtheruser(int UserID)
   {
       using (var context = new Context(DALBase.GetConnectionString()))
       {

              var usr = context.Users.FirstOrDefault(m => m.UserID == UserID);
           LoginUtils.Login(usr.LoginName, Crypto.Decrypt(usr.LoginPassword));
       }
   }

推荐答案

' #btnSwitchLogin')。on(' click' function (evt){
var query = ' 〜' + window location .pathname + window location .search;
var dto = {url:query};
('#btnSwitchLogin').on('click', function (evt) { var query = '~' + window.location.pathname + window.location.search; var dto = { url: query };


.ajax({
type: POST
url:MyHome.aspx / switchToOtheruser,
data: JSON .stringify(dto),
contentType: application / json; charset = utf-8
dataType: json
dto:{
UserID:
.ajax({ type: "POST", url: MyHome.aspx / switchToOtheruser, data: JSON.stringify(dto), contentType: "application/json; charset=utf-8", dataType: "json", dto: { UserID:


' # userList')。val()
}
});
});
('#userList').val() } }); });





和我的C#代码:





and my C# code:

public static void switchToOtheruser(int UserID)
   {
       using (var context = new Context(DALBase.GetConnectionString()))
       {

              var usr = context.Users.FirstOrDefault(m => m.UserID == UserID);
           LoginUtils.Login(usr.LoginName, Crypto.Decrypt(usr.LoginPassword));
       }
   }


这篇关于如何使用jquery修复ASP.NET中的401(未授权)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆