Reputation: 32500
I am making an AJAX call in my ASP.NET application via Jquery to a page method.
$.ajax({
type: "POST",
url: "APage.aspx/GetDropDowns",
data: "{'AId':'1'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
alert(msg.d);
},
error: function() {
alert('Error ');
}
[System.Web.Services.WebMethod]
public static string GetDropDowns(string Id)
{
return "Id was: " + Id;
}
I remember from using ASP.NET AJAX that the use of webservices was encouraged as opposed to page methods. However if I am enforcing JSON as above and doing a post is there A) any security flaw with the above and B) any reason to use a webservice rather than the page method
Upvotes: 1
Views: 1768
Reputation: 50002
A web method is essentially just a simple way of implementing a web service without creating a separate file etc. for it. There's nothing wrong with the code you've posted. @John's answer on the question 38421 referenced by @o.k.w. is a good summary of what you need to think about in terms of security.
Upvotes: 1
Reputation: 25820
A. Here's a good reply already in SO (Security advice for jquery ajax data post?)
B. The page postback method (or via Ajax UpdatePanel) has bigger overhead at the HTTP Post (especially the viewstate information, which carries a lot more data that are not required). Normal postback is more straightforward to implement though.
Upvotes: 0