I have solved this problem. Actually I did not consciously but probleb was fixed. I did Windows Updates after problem solved :) Updates shown below might be help another programmers.
The HTTP verb POST used to access path .... is not allowed
Question
I have a aspx file and I would like to request to WebMethod in same page with Ajax. However I get some error(you can see below) Actually this code worked before change my server.
Server config
- IIS 7.5
- .Net Framwork 4
- Windows Server 2008 R2
This is my Webmethod code in "Page.aspx"
[WebMethod]
public static string deleteOpenedSegment(decimal segmentID)
{
bool success = Helper.DeleteSegment(segmentID);
if (success)
{
return "true";
}
else
{
return "false";
}
}
And this is my Javascript method in Page.aspx
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");
}
});
And also this is capture about request from Google Chrome Web Developer Tool
Error Log
The HTTP verb POST used to access path '/............/Page.aspx/deleteOpenedSegment' is not allowed.
System.Web.HttpException The HTTP verb POST used to access path '/......./Page.aspx/deleteOpenedSegment' is not allowed.
System.Web.HttpException (0x80004005): The HTTP verb POST used to access path '/......./Page.aspx/getSegmentHistory' is not allowed.
at System.Web.DefaultHttpHandler.BeginProcessRequest(HttpContext context, AsyncCallback callback, Object state) at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step,Boolean& completedSynchronously)
Thanks in advance for any help or suggestions!
Solution
OTHER TIPS
Recently I have also use this type of code and I am able to delete my item without any problem, see my code
[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();
}