C# 为什么对webmethod的ajax调用从代码隐藏返回401?

C# 为什么对webmethod的ajax调用从代码隐藏返回401?,c#,asp.net,ajax,webforms,C#,Asp.net,Ajax,Webforms,阿贾克斯 我是ajax新手,正在构建一个图像验证页面。我想使用ajax将图像文本与asp文本框文本进行比较,以将文本框文本发送到代码隐藏中的web方法。在输出中,ajax调用写入success:true,但返回401(未经授权)代码。我做错了什么?此时,我正在尝试让调用正常工作,稍后将进一步填写webmethod。调试时会发生什么?您看过这个解决方案吗?调试时,它无法访问资源,因为服务器返回401。我确实看到了上面提到的帖子,当更改路由配置时,我现在得到一个500错误。500错误返回一个Argu

阿贾克斯


我是ajax新手,正在构建一个图像验证页面。我想使用ajax将图像文本与asp文本框文本进行比较,以将文本框文本发送到代码隐藏中的web方法。在输出中,ajax调用写入success:true,但返回401(未经授权)代码。我做错了什么?此时,我正在尝试让调用正常工作,稍后将进一步填写webmethod。

调试时会发生什么?您看过这个解决方案吗?调试时,它无法访问资源,因为服务器返回401。我确实看到了上面提到的帖子,当更改路由配置时,我现在得到一个500错误。500错误返回一个ArgumentException:Unknown web method verifyImage。
function verify() {
$.ajax({
    type: "POST",
    url: "Register.aspx/verifyImage",
    data: '{text: "' + $("#<%=TextBox4.ClientID%>")[0].value + '" }',
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function(response) {
        alert(response.d)
    },
    failure: function(response) {
        alert(response.d);
    }
});
}
[WebMethod]
    public void verifyImage(string text)
    {
        string imageString = Session["imageString"].ToString();
        if (imageString.Equals(text))
        {
            Response.Write("<script>alert('Memeber Page');</script>");
        }
        else
        {
            Response.Write("<script>alert('Incorrect');</script>");
        }
    }
<div style="height: 50px">
    <asp:Image ID="Image1" runat="server" />
    <asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
    <input id="Button1" type="button" value="Submit" onclick="verify()"/>
</div>
"name":"POST /Register.aspx/verifyImage","duration":"00:00:00.0161020","success":true,"responseCode":"401","url":"http://localhost:54506/Register.aspx/verifyImage","properties":{"DeveloperMode":"true","_MS.ProcessedByMetricExtractors":"(Name:'Requests', Ver:'1.0')