我有以下网络元素:
[WebMethod]
public static string SayHello()
{
if (HttpContext.Current.Session["UserData"] != null)
{
//do something
}
else
{
response.StatusCode = 401;
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.StatusCode = 401;
throw new HttpException(401, "timeout");
}
}
这就是电话:
$.ajax({
url: 'Default.aspx/SayHello',
type: 'POST',
contentType: 'application/json; charset=utf-8',
async: false,
dataType: "json",
data: '{ }',
success: function(Result) {
//do something
},
error: function(xhr, textStatus, errorThrown) {
xhr.StatusCode = 500
}
});
我总是在$ .ajax中得到500(内部服务器错误)状态代码错误var xhr.StatusCode 我可以在WebMethod中更改它吗?
我想将其更改为401(未授权)并将$ .ajaxError内部重定向到登录页面..