本文介绍了ASP.Net的WebMethod 405的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望有人可以解释为什么我可以在我的ASP.Net VB.Net的WebMethod attemping从JQuery的AJAX调用方法时,可以接收405错误的一些情况。

服务器实施

 <的WebMethod()GT; _
    公共共享功能的DoSomething(ID作为字符串)作为字符串
        昏暗VM中HssViewModel =新HssViewModel()        昏暗jResult作为字符串= JsonConvert.SerializeObject(VM)        返回jResult
   结束功能

Javscript执行:

  $阿贾克斯({
            键入:POST,
            网址:mypage.aspx / DoSomething的
            的contentType:应用/ JSON;字符集UTF-8
            数据:{ID:ABC12345},
            数据类型:JSON
            缓存:真实,
            更迭:功能(数据){
                上下文=数据;
                的console.log(数据);
            },
            错误:功能(错误){                的console.log(JQUERY错误响应:+ err.message);
            }
        });

我一直收到以下错误消息:

  POST HTTP://localhost/mypage.aspx/DoSomething 405(不允许的方法)

我也试图建立脚本方法标签,让一个GET请求,但后来我收到404

 < ScriptMethod(UseHttpGet:= TRUE,ResponseFormat:= ResponseFormat.Json)GT; _


解决方案

您的WebMethod期待一个GET请求:

 < ScriptMethod(UseHttpGet:= TRUE

但你在做一个POST请求:

  $。阿贾克斯({
     键入:POST,

一个405是由IIS抛出当HTTP动词(GET,PUT,POST,DELETE,HEAD等)请求,不支持/由指定的处理程序不允许的。

如果改变以上问题的差异仍然存在之后再看看你的IIS处理程序映射。

I'm hoping someone can shed some light on why I may be receiving a 405 errors on my ASP.Net VB.Net WebMethod when attemping to call from JQuery ajax method.

Server Implementation:

    <WebMethod()> _
    Public Shared Function DoSomething(id As String) As String
        Dim vm As HssViewModel = New HssViewModel()

        Dim jResult As String = JsonConvert.SerializeObject(vm)

        Return jResult
   End Function

Javscript Implementation:

  $.ajax({
            type: "POST",
            url: "mypage.aspx/DoSomething",
            contentType: "application/json; charset-utf-8",
            data: { 'id': 'ABC12345' },
            dataType: "json",
            cache: true,
            succes: function (data) {
                context = data;
                console.log(data);
            },
            error: function (err) {

                console.log("JQUERY ERROR RESPONSE: " + err.message);
            }
        });

I am consistently receiving the following error message:

POST http://localhost/mypage.aspx/DoSomething 405 (Method Not Allowed)

I have also tried setting up the script method tag to allow a GET request but then I receive a 404

  <ScriptMethod(UseHttpGet:=True, ResponseFormat:=ResponseFormat.Json)> _
解决方案

Your WebMethod is expecting a GET request:

<ScriptMethod(UseHttpGet:=True

but you are doing a POST request:

$.ajax({
     type: "POST",

A 405 is thrown by IIS when an HTTP verb(GET,PUT,POST,DELETE,HEAD,etc.) is requested and is not supported/disallowed by the designated handler.

If after changing the discrepancy above the problem persist then look at your iis handler mappings.

这篇关于ASP.Net的WebMethod 405的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 09:08