Click here to Skip to main content
15,867,568 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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:

JavaScript
$('#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()
           }
       });
   });


and my C# code:

C#
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));
       }
   }
Posted
Updated 21-Dec-22 21:43pm
Comments
Member 11770244 13-Jul-16 13:13pm    
http://localhost:1971/MyHome.aspx/switchToOtheruser Failed to load resource: the server responded with a status of 401 (Unauthorized),the above issue was i am getting please provide me any solutions for the above.
What is this?

dto: {
UserID: $('#userList').val()
}
Member 11770244 14-Jul-16 5:09am    
dto: {
UserID: $('#userList').val()
}
i am sending dropdownlist selected value to code behind
ZurdoDev 13-Jul-16 13:51pm    
You are unauthorized. I'm not sure what you want us to do.
Member 11770244 14-Jul-16 5:16am    
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));
}
}

and it is a web method

 
Share this answer
 
Hi My solution was in RouteConfig.cs file set settings.AutoRedirectMode = RedirectMode.Off;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900