我正在像这样在 Win2003Srv 上的 IIS6 下对 WebMethod 进行 AJAX 调用,它工作正常:
<System.Web.Services.WebMethod()> _
Public Shared Sub EmailManagers()
'code
End Sub
使用这样的 AJAX 调用:
function EmailManagers_Click() {
alert('staring email send');
$.ajax({
type: "POST",
//url: "EACApprovalOverview.aspx/EmailManagers(" + document.URL + ")",
url: "EACApprovalOverview.aspx/EmailManagers",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
alert("Emails Sent!");
},
fail: function (msg) {
alert("Email Send Failed!");
}
});
alert('end email send');
return false;
};
当我在 Win2008Srv 上的 IIS7.5 下运行此应用程序时,我得到“对象引用未设置为对象的实例”。这是堆栈跟踪:
[NullReferenceException: Object reference not set to an instance of an object.]
System.Web.Handlers.ScriptModule.OnPostAcquireRequestState(Object sender, EventArgs eventArgs) +162
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +68
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75
我在此处的帖子中看到的其他错误包含堆栈跟踪顶部的附加行,如下所示:
at System.Web.Script.Services.WebServiceData.GetMethodData(String methodName)
at System.Web.Handlers.ScriptModule.OnPostAcquireRequestState(Object sender, EventArgs eventArgs)
at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
由于我没有进行 WebServiceData.GetMethodData 调用,我猜测 System.Web.Handlers 没有正确加载,导致 ScriptModule 为空。
我的 web.config 中有这个:
<httpModules>
<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</httpModules>
并且我已确保已安装 .net 3.5 sp1。我什至检查了 GAC 并且 dll 在那里。我在看什么?