简体   繁体   English

来自jquery AJAX的调用webmethod中的身份验证失败

[英]Authentication failed in call webmethod from jquery AJAX

In here i call webmethod from Jquery Ajax.In the success function i saw there's a error called "Authentication Failed" 在这里,我从Jquery Ajax调用webmethod。在成功函数中,我看到有一个错误称为“身份验证失败”

Here i have atached error image 在这里,我有错误的图像 错误

My WebMethod 我的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;
}

My Ajax Function 我的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>

In my Web.Config file 在我的Web.Config文件中

<location path="WebMethods.aspx">
<system.web>
  <authorization>
    <allow users="*"/>
  </authorization>
</system.web>

I found the answer 我找到了答案

Just comment below line in RouteConfig file 只需在RouteConfig文件中的下面注释

 //settings.AutoRedirectMode = RedirectMode.Permanent;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM