【发布时间】:2014-01-11 04:16:56
【问题描述】:
在研究这个问题时,大多数 SO 问题都与 static 方法有关。
由于它不能与真正的(并且有点复杂)WebMethod 一起使用,我刚刚创建了一个简单的方法来检查是否可以使用该方法本身。
[WebMethod]
[ScriptMethod(UseHttpGet = false)]
public static string HelloWorld()
{
return "Hello World!";
}
电话。
<script>
$(document).ready(function () {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "usersWebMethods.aspx/HelloWorld",
dataType: "json",
success: function (data) {
alert(data.d);
}
});
});
</script>
总是归结为500 (Internal Server Error)
Unknown web method HelloWorld.
Parameter name: methodName
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentException: Unknown web method HelloWorld.
Parameter name: methodName
为什么会失败?
【问题讨论】:
-
static网络方法是not supported。 -
也许我全都错了,或者我没有正确解释自己。这只是一个在代码隐藏中使用 webmethods 的 .aspx 页面。这不是网络服务。
-
啊,好的,您使用的是 ScriptManager 吗?如果是这样,您是否启用了EnableScriptMethods?
-
不,只是使用 jQuery,我确信不需要使用 ScriptManager
-
承认这一点很尴尬,但我的问题是因为该方法的访问修饰符是私有的而不是公共的......
标签: c# asp.net ajax pagemethods