使用自定义 httpmodule 并具有“Sys”;是未定义的错误

发布于 2024-08-17 16:34:19 字数 1690 浏览 6 评论 0原文

我创建了自己的自定义 httpmodule 来处理 url 重写,以便像 www.contoso.com/help/default.aspx 这样的 url 将指向 www.contoso.com/default.aspx code> 实际资源所在的位置。

这工作正常,但由于我实现了 httpmodule,我遇到了 ScriptResource.axd 无法正确运行以添加执行按钮单击或 ajax 提供的功能所需的 javascript 的问题。

我将 IIS7 设置为使用经典管道应用程序池。我还确保 web.config 文件中包含必要的信息。

我已将此信息粘贴在下面。有人可以找出我遗漏或应该以不同方式配置的内容吗?

<httpHandlers>
            <remove verb="*" path="*.asmx" />
                <remove  path="WebResource.axd" verb="GET" />
            <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=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
            <add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false" />
      <add verb="*" path="*.aspx" type="myHandler" />
      <add path="WebResource.axd" verb="GET" type="System.Web.Handlers.AssemblyResourceLoader" validate="True" />
        </httpHandlers>
        <httpModules>
            <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
      <add name="myModule" type="myModule" />
        </httpModules>

I have created my own custom httpmodule to handle url rewriting so that urls like www.contoso.com/help/default.aspx will point to www.contoso.com/default.aspx where the actual resource is located.

This works fine, but because of my implementation of an httpmodule I am having problems with ScriptResource.axd not being run properly to add the javascript needed to perform button clicks or functionality afforded by ajax.

I have IIS7 set to use the classic pipeline app pool. I have also ensured that the web.config file has the necessary information in it.

I have pasted this information below. Can someone identify something that I have missed or should have configured differently?

<httpHandlers>
            <remove verb="*" path="*.asmx" />
                <remove  path="WebResource.axd" verb="GET" />
            <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=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
            <add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false" />
      <add verb="*" path="*.aspx" type="myHandler" />
      <add path="WebResource.axd" verb="GET" type="System.Web.Handlers.AssemblyResourceLoader" validate="True" />
        </httpHandlers>
        <httpModules>
            <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
      <add name="myModule" type="myModule" />
        </httpModules>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

撕心裂肺的伤痛 2024-08-24 16:34:19

尝试将类似的内容添加到您的自定义 httpmodule 中:

public class MyModule : IHttpModule
{
    public MyModule()
    {
    }

    private void Application_OnAfterProcess(Object source, EventArgs e)
    {
        HttpApplication application = (HttpApplication)source;
        HttpContext context = application.Context;

        if (context.Request.Headers["x-microsoftajax"] == null)
        {
            if ((!System.IO.File.Exists(application.Request.PhysicalPath)) &&
                (!application.Request.Url.ToString().Contains(".axd")) &&
                (!application.Request.Url.ToString().Contains(".asmx")))
                {
                    string newUrl = "~/Search.aspx?q=" 
                        + context.Server.UrlEncode(application.Request.Url.Segments.Last());
                        ...
                    context.RewritePath(newUrl);
                }
            }
        }
    }

    void IHttpModule.Init(HttpApplication context)
    {    
         context.PostResolveRequestCache += (new EventHandler(this.Application_OnAfterProcess));
    }
}

Try adding something like this to your custom httpmodule:

public class MyModule : IHttpModule
{
    public MyModule()
    {
    }

    private void Application_OnAfterProcess(Object source, EventArgs e)
    {
        HttpApplication application = (HttpApplication)source;
        HttpContext context = application.Context;

        if (context.Request.Headers["x-microsoftajax"] == null)
        {
            if ((!System.IO.File.Exists(application.Request.PhysicalPath)) &&
                (!application.Request.Url.ToString().Contains(".axd")) &&
                (!application.Request.Url.ToString().Contains(".asmx")))
                {
                    string newUrl = "~/Search.aspx?q=" 
                        + context.Server.UrlEncode(application.Request.Url.Segments.Last());
                        ...
                    context.RewritePath(newUrl);
                }
            }
        }
    }

    void IHttpModule.Init(HttpApplication context)
    {    
         context.PostResolveRequestCache += (new EventHandler(this.Application_OnAfterProcess));
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文