【问题标题】:The HTTP verb POST used to access path .... is not allowed用于访问路径的 HTTP 动词 POST .... 是不允许的
【发布时间】:2014-02-22 11:14:33
【问题描述】:

我有一个 aspx 文件,我想使用 Ajax 在同一页面中向 WebMethod 请求。但是我得到了一些错误(你可以在下面看到)实际上这段代码在改变我的服务器之前就已经工作了。

服务器配置

  • IIS 7.5
  • .Net 框架 4
  • Windows Server 2008 R2

这是我在“Page.aspx”中的 Webmethod 代码

[WebMethod]
public static string deleteOpenedSegment(decimal segmentID)
{
    bool success = Helper.DeleteSegment(segmentID);
    if (success)
    {
        return "true";
    }
    else
    {
        return "false";
    }
}

这是我在 Page.aspx 中的 Javascript 方法

jQuery.ajax({
       url: 'Page.aspx/deleteOpenedSegment',
       type: "POST",
       data: "{'segmentID':" + getSelectedSegment().attr('id') + "}",
       contentType: "application/json; charset=utf-8",
       dataType: "json",
       success: function (data) {
                  alert("okey");
                }
       });

这也是关于来自 Google Chrome Web Developer Tool 的请求的捕获

错误日志

用于访问路径的 HTTP 动词 POST '/............/Page.aspx/deleteOpenedSegment' 是不允许的。

System.Web.HttpException 不允许用于访问路径“/......./Page.aspx/deleteOpenedSegment”的 HTTP 动词 POST。

System.Web.HttpException (0x80004005):不允许使用 HTTP 动词 POST 访问路径“/......./Page.aspx/getSegmentHistory”。
在 System.Web.DefaultHttpHandler.BeginProcessRequest(HttpContext 上下文,AsyncCallback 回调,对象状态) 在 System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
在 System.Web.HttpApplication.ExecuteStep(IExecutionStep step,Boolean& completedSynchronously)

提前感谢您的任何帮助或建议!

【问题讨论】:

  • 您要删除什么,是要删除的文件吗?

标签: c# asp.net ajax webforms webmethod


【解决方案1】:

我已经解决了这个问题。其实我没有自觉,但问题是固定的。问题解决后我做了 Windows 更新 :) 下面显示的更新可能对其他程序员有所帮助。

【讨论】:

    【解决方案2】:

    最近我也使用了这种类型的代码,我可以毫无问题地删除我的项目,请参阅我的代码

     [System.Web.Services.WebMethod()]
            public static string DeleteCartItem(string catId)
            {
                Customer thisCustomer = Customer.Current;
                var cart = new ShoppingCart(thisCustomer.SkinID, thisCustomer, CartTypeEnum.ShoppingCart, 0, false);
                cart.RemoveItem(Convert.ToInt32(catId), false);
                var path = System.Web.HttpContext.Current.Server.MapPath("22-02-2014__000865.jpg");  
                File.Delete(path);
                return cart.TotalQuantity().ToString();    
        } 

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-07-11
      • 2011-06-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多