JQuery调用asmx报错【未能执行 URL】

jeremyyang824 2013-05-03 02:08:03
webservice

[WebService(Namespace = "http://test")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[System.Web.Script.Services.ScriptService]
public class Equipment : System.Web.Services.WebService
{
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string GetOperatorDefaultEquipCode(string operatorNum)
{
return "a";
}

web.config

<httpModules>
<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</httpModules>
<httpHandlers>
<remove verb="*" path="*.asmx"/>
<add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false" />

</httpHandlers>


jquery js

$('#test').blur(function(){
$.ajax({
type: "POST",
url: '/WebService/Equipment.asmx/GetOperatorDefaultEquipCode',
cache: false,
contentType: "application/json; charset=utf-8",
data: "{operatorNum:'001'}",
dataType: "json",
success: function (data, status) {
if (data.d) {
...
}
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
debugger;

}
});
});


执行报错, error function中XMLHttpRequest的信息如下:

<html>
<head>
<title>未能执行 URL。</title>
<style>
body {font-family:"Verdana";font-weight:normal;font-size: .7em;color:black;}
p {font-family:"Verdana";font-weight:normal;color:black;margin-top: -5px}
b {font-family:"Verdana";font-weight:bold;color:black;margin-top: -5px}
H1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red }
H2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon }
pre {font-family:"Lucida Console";font-size: .9em}
.marker {font-weight: bold; color: black;text-decoration: none;}
.version {color: gray;}
.error {margin-bottom: 10px;}
.expandable { text-decoration:underline; font-weight:bold; color:navy; cursor:hand; }
</style>
</head>

<body bgcolor="white">

<span><H1>“/JMES”应用程序中的服务器错误。<hr width=100% size=1 color=silver></H1>

<h2> <i>未能执行 URL。</i> </h2></span>

<font face="Arial, Helvetica, Geneva, SunSans-Regular, sans-serif ">

<b> 说明: </b>执行当前 Web 请求期间,出现未经处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。

<br><br>

<b> 异常详细信息: </b>System.Web.HttpException: 未能执行 URL。<br><br>

<b>源错误:</b> <br><br>

<table width=100% bgcolor="#ffffcc">
<tr>
<td>
<code>

执行当前 Web 请求期间生成了未经处理的异常。可以使用下面的异常堆栈跟踪信息确定有关异常原因和发生位置的信息。</code>

</td>
</tr>
</table>

<br>

<b>堆栈跟踪:</b> <br><br>

<table width=100% bgcolor="#ffffcc">
<tr>
<td>
<code><pre>

[HttpException (0x80004005): 未能执行 URL。]
System.Web.Hosting.ISAPIWorkerRequestInProcForIIS6.BeginExecuteUrl(String url, String method, String childHeaders, Boolean sendHeaders, Boolean addUserIndo, IntPtr token, String name, String authType, Byte[] entity, AsyncCallback cb, Object state) +2447593
System.Web.HttpResponse.BeginExecuteUrlForEntireResponse(String pathOverride, NameValueCollection requestHeaders, AsyncCallback cb, Object state) +417
System.Web.DefaultHttpHandler.BeginProcessRequest(HttpContext context, AsyncCallback callback, Object state) +192
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +8968404
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +184
</pre></code>

</td>
</tr>
</table>

<br>

<hr width=100% size=1 color=silver>

<b>版本信息:</b> Microsoft .NET Framework 版本:4.0.30319; ASP.NET 版本:4.0.30319.272

</font>

</body>
</html>
<!--
[HttpException]: 未能执行 URL。
在 System.Web.Hosting.ISAPIWorkerRequestInProcForIIS6.BeginExecuteUrl(String url, String method, String childHeaders, Boolean sendHeaders, Boolean addUserIndo, IntPtr token, String name, String authType, Byte[] entity, AsyncCallback cb, Object state)
在 System.Web.HttpResponse.BeginExecuteUrlForEntireResponse(String pathOverride, NameValueCollection requestHeaders, AsyncCallback cb, Object state)
在 System.Web.DefaultHttpHandler.BeginProcessRequest(HttpContext context, AsyncCallback callback, Object state)
在 System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
在 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
-->


以前项目都这样用,应该是OK的,这个项目中 这里就会报 未能执行 URL。
服务器.netFramework 4.0 IIS7
...全文
299 18 打赏 收藏 转发到动态 举报
写回复
用AI写文章
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
jeremyyang824 2013-05-03
  • 打赏
  • 举报
回复
引用 15 楼 liuchaolin 的回复:
[quote=引用 14 楼 jeremyyang824 的回复:] 是这样的,系统布局是用iframe来布局的,分为上、左、中三块,左边是菜单,中间菜单对应的模块页面,这个页面是嵌入在中间的一块。 刚才又深入测试了一下,发现之所以iframe中不行,是因为我都是从登陆->系统主页->点击模块->然后测试该页面的。 而脱离iframe之所以行,是因为,我没有登陆系统,就直接打了该页面的url。 如果纯粹在iframe中运行该页面,我试了是ok的,那应该就每个请求的Application_AuthenticateRequest中的问题了,我看了 Application_AuthenticateRequest中貌似有对cookie的相关操作。 看来我要去深入研究下,晕死了。。。。。 谢谢楼上大哥的帮助。。。
有没有试过,把IE浏览器关闭掉,重新打开呢?[/quote] 找到问题了... Global.asax中

protected void Application_AuthenticateRequest(object sender, EventArgs e)
{
    if (Request.IsAuthenticated)
    {
        string username = Context.User.Identity.Name;
        IApplicationContext ctx = ContextRegistry.GetContext();
        IAuthenticationService authenticationService = (IAuthenticationService)ctx["Portal.IAuthenticationService"];
        IPrincipal principal = authenticationService.CreateAuthenticatePrincipal(username);
        Context.User = principal; //设置当前用户的认证凭证
    }
}
通过js调用的webservice,在AuthenticateRequest的时候无法从IOC容器中获取对象,用的是Spring.net。真是神奇。 改成下面这样就可以了...只是这样的话asmx中就不能获取到当前用户的认证信息了

private static readonly string[] filterExtension = new string[] { ".asmx" };
protected void Application_AuthenticateRequest(object sender, EventArgs e)
{
    if (Request.IsAuthenticated && !filterExtension.Contains(Request.CurrentExecutionFilePathExtension))    //过滤特定请求
    {
        string username = Context.User.Identity.Name;
        IApplicationContext ctx = ContextRegistry.GetContext();
        IAuthenticationService authenticationService = (IAuthenticationService)ctx["Portal.IAuthenticationService"];
        IPrincipal principal = authenticationService.CreateAuthenticatePrincipal(username);
        Context.User = principal; //设置当前用户的认证凭证
    }
}
jeremyyang824 2013-05-03
  • 打赏
  • 举报
回复
我先去用fiddler查下请求内容有什么线索
jeremyyang824 2013-05-03
  • 打赏
  • 举报
回复
有啊 应该不是缓存的关系,貌似是在每个请求解析FormsAuthenticationTicket时有什么问题。 之前已经换成不用webservice来做ajax了,也已经好了,但是总觉得心里不爽,想找找究竟是什么问题导致ScriptService出问题。
md5e 2013-05-03
  • 打赏
  • 举报
回复
引用 14 楼 jeremyyang824 的回复:
是这样的,系统布局是用iframe来布局的,分为上、左、中三块,左边是菜单,中间菜单对应的模块页面,这个页面是嵌入在中间的一块。 刚才又深入测试了一下,发现之所以iframe中不行,是因为我都是从登陆->系统主页->点击模块->然后测试该页面的。 而脱离iframe之所以行,是因为,我没有登陆系统,就直接打了该页面的url。 如果纯粹在iframe中运行该页面,我试了是ok的,那应该就每个请求的Application_AuthenticateRequest中的问题了,我看了 Application_AuthenticateRequest中貌似有对cookie的相关操作。 看来我要去深入研究下,晕死了。。。。。 谢谢楼上大哥的帮助。。。
有没有试过,把IE浏览器关闭掉,重新打开呢?
jeremyyang824 2013-05-03
  • 打赏
  • 举报
回复
是这样的,系统布局是用iframe来布局的,分为上、左、中三块,左边是菜单,中间菜单对应的模块页面,这个页面是嵌入在中间的一块。 刚才又深入测试了一下,发现之所以iframe中不行,是因为我都是从登陆->系统主页->点击模块->然后测试该页面的。 而脱离iframe之所以行,是因为,我没有登陆系统,就直接打了该页面的url。 如果纯粹在iframe中运行该页面,我试了是ok的,那应该就每个请求的Application_AuthenticateRequest中的问题了,我看了 Application_AuthenticateRequest中貌似有对cookie的相关操作。 看来我要去深入研究下,晕死了。。。。。 谢谢楼上大哥的帮助。。。
md5e 2013-05-03
  • 打赏
  • 举报
回复
想不明白,为什么用jquery ajax了还要用iframe来调用呢?
jeremyyang824 2013-05-03
  • 打赏
  • 举报
回复
引用 11 楼 liuchaolin 的回复:
[quote=引用 10 楼 jeremyyang824 的回复:] 谢谢这个大哥~ 我又发现一个奇怪的情况。。。。。 这个通过Jq调用WebService的页面是在iframe中的。但都是同一个webApp下,不存在跨域问题。 如果我重启IIS后,将该页面单独运行,不放在iframe中,则一切OK。 如果在iframe下调用,会发生上述异常;并且此时,再脱离iframe调用也会发生异常(已清理过IE缓存,应该不是IE缓存)。 这。。。。。。
那你是怎么调用的?[/quote] 之前缓存没清干净,刚又试了几次,没一次请求清一次缓存,明确了问题: 1.同一个页面,如果在iframe下,页面中调用webservice的jquery ajax就会报错“未能执行URL”。 2.如果不在iframe下直接访问该页面,则页面中调用webservice的jquery ajax正常获得结果。
md5e 2013-05-03
  • 打赏
  • 举报
回复
引用 10 楼 jeremyyang824 的回复:
谢谢这个大哥~ 我又发现一个奇怪的情况。。。。。 这个通过Jq调用WebService的页面是在iframe中的。但都是同一个webApp下,不存在跨域问题。 如果我重启IIS后,将该页面单独运行,不放在iframe中,则一切OK。 如果在iframe下调用,会发生上述异常;并且此时,再脱离iframe调用也会发生异常(已清理过IE缓存,应该不是IE缓存)。 这。。。。。。
那你是怎么调用的?
jeremyyang824 2013-05-03
  • 打赏
  • 举报
回复
谢谢这个大哥~ 我又发现一个奇怪的情况。。。。。 这个通过Jq调用WebService的页面是在iframe中的。但都是同一个webApp下,不存在跨域问题。 如果我重启IIS后,将该页面单独运行,不放在iframe中,则一切OK。 如果在iframe下调用,会发生上述异常;并且此时,再脱离iframe调用也会发生异常(已清理过IE缓存,应该不是IE缓存)。 这。。。。。。
md5e 2013-05-03
  • 打赏
  • 举报
回复


只有先配置这个试试看了
jeremyyang824 2013-05-03
  • 打赏
  • 举报
回复
本地开发环境下 通过VS的虚拟服务器都是好的,应该还是出在IIS7上。 我本地并未使用MVC,而是传统的ASP.NET WebForm
md5e 2013-05-03
  • 打赏
  • 举报
回复
<system.webServer> <validation validateIntegratedModeConfiguration="false"/> <modules runAllManagedModulesForAllRequests="true"> <add name="UrlRewriter" type="Intelligencia.UrlRewriter.RewriterHttpModule" /> <add name="ScriptModule" preCondition="integratedMode" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/> </modules> <handlers> <remove name="WebServiceHandlerFactory-Integrated"/> <add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/> <add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/> <add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/> </handlers> </system.webServer>
md5e 2013-05-03
  • 打赏
  • 举报
回复
还有iis7.0以上版本还要多配置这里
md5e 2013-05-03
  • 打赏
  • 举报
回复
个人认为是 <add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" /> <add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false" /> 这两个版本太低的原因
jeremyyang824 2013-05-03
  • 打赏
  • 举报
回复
引用 2 楼 liuchaolin 的回复:
参考 http://bbs.csdn.net/topics/360193668
这帖子看过了,也试过 不行,我请求的路径并非是那些静态资源。
md5e 2013-05-03
  • 打赏
  • 举报
回复
http://q.cnblogs.com/q/28702/
md5e 2013-05-03
  • 打赏
  • 举报
回复
参考 http://bbs.csdn.net/topics/360193668
jeremyyang824 2013-05-03
  • 打赏
  • 举报
回复
而且比较奇怪的是,先通过localhost的webservice测试页面调用服务 一切OK。 如果通过JQuery调用,报错之后,再通过localhost的webservice测试页面调用服务 就会报同样的错误。。。 我怀疑是 “/WebService/Equipment.asmx/GetOperatorDefaultEquipCode”的路径格式 ISAPI路由错误?

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧