c ajax 调用webservice,从ajax调用本地C#webservice,401错误未经授权(Call a local C# webservice from ajax , 401 error...

I have a problem with a login function that is called by ajax , that's the code of the function it's a webservice visible

[WebMethod]

[System.Web.Script.Services.ScriptMethod]

public string CheckData(string login, string Pass)

{

global gb = new global();

if (gb.CheckUserExist(login, Pass))

{

System.Web.Security.FormsAuthentication.RedirectFromLoginPage(login, true);

HttpCookie cookie = new HttpCookie("userData",login);

cookie.Expires = DateTime.Now.AddMonths(2);

Mosab2aModel.Mosab2aEntities context = new Mosab2aModel.Mosab2aEntities();

var User = context.Users.Where(x => x.UserName == login && x.Password == Pass)

.Select(x => new { x.UserName, x.Password, x.Admin, x.DisplayName, x.FBID }).First();

cookie["UserName"] = User.UserName;

cookie["Password"] = User.Password;

cookie["isAdmin"] = User.Admin.ToString();

cookie["Name"] = User.DisplayName;

cookie["FBID"] = User.FBID;

Context.Response.Cookies.Add(cookie);

//Context.Response.Redirect("/Default.aspx");

return "1";

}

else

{

return "0";

}

}

I call it by ajax here

$.ajax({

type: "POST",

url: 'LoginService.asmx/CheckData',

data: "{'login':'"+ login +"','Pass':'"+pass +"'}",

contentType: "application/json; charset=utf-8",

dataType: "json",

success: function(msg)

{

if (msg.d == "1")

{

//document.location.href = '/Default.aspx';

}

else

{

formWrapper.clearMessages();

displayError('Username or password is incorrect');

}

},

error: function()

{

formWrapper.clearMessages();

displayError('Error in contacting server , try again later.');

}

});

I have a strange problem if the user doesn't exist , the function works well and it return the value of 0 and the error diplays , but If the function found the user it get an 401 error Unauthorized.

edit: after several search the problem is with this line !

System.Web.Security.FormsAuthentication.RedirectFromLoginPage(login, true);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值