jQuery AJAX调用Web方法中的身份验证失败 [英] Authentication failed in call webmethod from jquery AJAX
本文介绍了jQuery AJAX调用Web方法中的身份验证失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在这里,我从Jquery Ajax调用webmethod.在成功函数中,我看到了一个名为身份验证失败"的错误
In here i call webmethod from Jquery Ajax.In the success function i saw there's a error called "Authentication Failed"
在这里我遇到了错误图片
Here i have atached error image
我的WebMethod
My WebMethod
[WebMethod,ScriptMethod]
public static List<UploadedFiles> GetAllUploadedFiles()
{
List<UploadedFiles> UploadedFilesDetails = new List<UploadedFiles>();
try
{
SqlCommand comGetAllFiles = new SqlCommand("SP_GetAllUploadedFiles", conDB);
comGetAllFiles.CommandType = CommandType.StoredProcedure;
if (conDB.State == ConnectionState.Closed)
conDB.Open();
SqlDataReader rdr = comGetAllFiles.ExecuteReader();
DataTable dt = new DataTable();
dt.Load(rdr);
foreach (DataRow r in dt.Rows)
{
UploadedFilesDetails.Add(new UploadedFiles
{
Id = (int)r["Id"],
UserId =(Guid)r["UserId"],
FilePath = r["FilePath"].ToString(),
Date =(DateTime) r["Date"]
});
}
}
catch(Exception ee)
{
}
finally
{
conDB.Close();
}
return UploadedFilesDetails;
}
我的Ajax函数
<script>
$(function () {
LoadUploadFiles();
});
function LoadUploadFiles() {
var url = '<%=ResolveUrl("WebMethods.aspx/GetAllUploadedFiles") %>';
$.ajax({
url: url,
type: "post",
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function (Result) {
debugger;
$.each(Result.d, function (key, value) {
alert("y");
$("#uploaddata").append($("<table><tr></tr></table>").val
(value.Id).html(value.FilePath));
});
},
error: function (e, x) {
alert(x.ResponseText);
}
});
}
</script>
在我的Web.Config文件中
In my Web.Config file
<location path="WebMethods.aspx">
<system.web>
<authorization>
<allow users="*"/>
</authorization>
</system.web>
推荐答案
我找到了答案
只需在RouteConfig文件中的行下方注释
Just comment below line in RouteConfig file
//settings.AutoRedirectMode = RedirectMode.Permanent;
这篇关于jQuery AJAX调用Web方法中的身份验证失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文