【问题标题】:Asp.net Routing, WebServices, and IIS7 ClassicAsp.net 路由、WebServices 和 IIS7 经典
【发布时间】:2010-10-26 00:15:42
【问题描述】:

我有一个在 IIS7 Classic 上运行的 Web 表单应用程序。它利用 .asmx 样式的 Web 服务为网站的客户端重部分提供服务。

我们的任务是在“友好 url”中分层,并决定使用新的 Asp.net 路由。我们在 IIS 中有一条规则将 所有请求 映射到 aspnet_isapi.dll,这会在我们的 web.config (system.webServer/hanlers) 中产生这个声明:

<add name="asp.net routing" path="*" verb="*" modules="IsapiModule" scriptProcessor="C:\Windows\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll" resourceType="Unspecified" preCondition="classicMode,runtimeVersionv2.0,bitness32" />

但现在路由会破坏我们的 .asmx Web 服务请求(形式为 http://example.com/blah.asmx/SomeMethod)。对 Web 服务的任何请求都会给我们带来无穷乐趣:

Failed to Execute URL.
[HttpException (0x80004005): Failed to Execute 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) +2004885
System.Web.HttpResponse.BeginExecuteUrlForEntireResponse(String pathOverride, NameValueCollection requestHeaders, AsyncCallback cb, Object state) +393
System.Web.DefaultHttpHandler.BeginProcessRequest(HttpContext context, AsyncCallback callback, Object state) +223
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +8677954
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&amp; completedSynchronously) +155

将此行放入我们的路线设置中:

routes.Add(new Route("{service}.asmx/{*pathInfo}", new StopRoutingHandler()));

仍然给我们留下“无法执行 URL”异常。我知道这条路线是匹配的:

public sealed class DieHandler : IRouteHandler
{
    #region IRouteHandler Members

    public IHttpHandler GetHttpHandler(RequestContext requestContext)
    {
        throw new NotImplementedException();
    }

    #endregion
}
routes.Add(new Route("{service}.asmx/{*pathInfo}", new DieHandler()));

使用该路由而不是“无法执行 URL”,我会看到“方法未实现”,就像我预期的那样。

我怀疑我们的 * -> aspnet_isapi.dll 正在造成严重破坏,因为我在搜索 google 时没有发现其他人这样做。

提前感谢您的任何见解。

【问题讨论】:

    标签: web-services iis-7 asmx asp.net-routing


    【解决方案1】:

    需要在web.config中的handler中添加requireAccess="None",即:

    <add name="aspnet_isapi 32-bit" path="*" verb="*" modules="IsapiModule" scriptProcessor="C:\Windows\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll" resourceType="Unspecified" requireAccess="None" preCondition="classicMode,runtimeVersionv2.0,bitness32" />
    

    这样可以正确处理文件

    【讨论】:

      【解决方案2】:
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-11
      • 2011-10-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多