404 的 httpModule

发布于 2024-09-25 09:15:27 字数 626 浏览 4 评论 0原文

我创建了一个 httpModule 来处理 URL 重新映射,它在我的测试系统上运行得很好。对 www.mydomain.com/Some_Fancy_URL 的请求将被重写为 www.mydomain.com/some.aspx?fancy=23 等等。

当我部署到实际网站时,我得到了默认的 IIS 404 页面。

在网上做了一些研究后,我似乎需要在 IIS 6 中设置“通配符映射”,以使请求通过 IIS 并进入我的 httpModule。问题是该站点托管在共享服务器上,因此可能无法让 ISP 进行更改。

我的问题是,我不能使用 httpHandler 告诉 IIS 我希望如何处理这些请求吗?例如:

<httpHandlers>
  <add path="*.aspx" verb="GET,POST" type="System.Web.UI.PageHandlerFactory" validate="false"/>
</httpHandlers>

将其添加到我的 Web.Config 中似乎应该告诉 IIS 停止验证 .aspx 文件的存在,而只是将请求传递给我来处理。但这不起作用。

有什么建议吗?

I've created an httpModule to handle URL remappings, and it works great on my test system. A request for www.mydomain.com/Some_Fancy_URL gets rewritten to www.mydomain.com/some.aspx?fancy=23 and so on.

When I deploy to the actual web site, I'm getting the default IIS 404 page though.

After doing some research online, it would seem that I need to setup "Wildcard Mapping" in IIS 6 to get the request past IIS and in to my httpModule. The problem is that the site is hosted on a shared server, so it may not be possible to get the ISP to make that change.

My question is, can't I use an httpHandler to tell IIS how I want these requests handled? For example:

<httpHandlers>
  <add path="*.aspx" verb="GET,POST" type="System.Web.UI.PageHandlerFactory" validate="false"/>
</httpHandlers>

It would seem like adding this to my Web.Config should tell IIS to stop validating the existence of .aspx files, and just pass the request along for me to process. It doesn't work though.

Any suggestions?

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

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

发布评论

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

评论(2

撩人痒 2024-10-02 09:15:27

IIS 6 和 ASP.NET 的问题在于它们没有集成。 IIS 需要通过脚本映射(.aspx、.asmx、通配符等)了解 ASP.NET。

您的任何 web.config 配置设置都不会影响 IIS,因为 web.config 是用来配置 ASP.NET 的行为,而不是 IIS。 IIS 不了解 web.config

除非您可以将请求移交给 ASP.NET 管道(通过脚本映射),否则什么都不会发生,并且您的所有 web.config 设置都将被忽略。

对于 IIS 7,情况就完全不同了。在 IIS7 中,ASP.NET 和 IIS 紧密集成并共享相同的管道,从而允许您实现所需的结果。

另一种方法可能是查明您的托管服务商是否在其服务器上运行了 URL 重写器,例如 ISAPI_Rewrite。这样您就可以重写 url,而无需将通配符脚本映射映射到 IIS6。

The problem with IIS 6 and ASP.NET is that they're aren't integrated. IIS needs to be told about ASP.NET via script mappings (.aspx, .asmx, wildcard and so on).

None of your web.config configuration settings will influence IIS because web.config is there to configure ASP.NET's behaviour, not IIS. IIS has no knowledge of web.config.

Unless you can hand off a request to the ASP.NET pipeline (via a script map) nothing will happen and all your web.config settings will be ignored.

With IIS 7 the story is quite different. In IIS7, ASP.NET and IIS are closely integrated and share the same pipeline thus permitting you to achieve the result you're looking for.

The alternative may be to find out if your hoster runs a URL rewriter such as ISAPI_Rewrite on their servers. That way you could rewrite urls without having to map a wildcard scriptmap to IIS6.

夜光 2024-10-02 09:15:27

通过一些尝试和错误,以及更多的网络搜索,我找到了解决方案。它本质上与凯夫的回答相似。

除非请求具有已知的文件扩展名(.aspx、.ascx 等),否则 IIS 不会将请求视为 .NET。当我发送诸如 www.mydomain.com/anything 之类的内容时,它会查找名为“anything”的文件或文件夹,当找不到时,它就会转到默认的 IIS 404处理程序。

那就是我接管的地方。我更改了 IIS 6,将 404 问题转发到 /404.aspx。然后,我创建了该页面,其中包含通用的“找不到您的文件”消息,其样式与我的网站相同。

这是好的部分:现在 IIS 正在将 404 发送到 .NET 页面,我创建的自定义 httpModule 被解雇。该请求针对 404.aspx,但 IIS 也足够好,可以附加原始 URL。你会得到类似这样的信息:

www.mydomain.com/404.aspx?404;http://www.mydomain.com/anything

这允许我解析 httpModule 中的请求,并根据需要重写!

Through some trial and error, along with more web searches, I found a solution. It essentially parallels Kev's answer.

IIS won't treat a request as .NET unless it has a known file extension (.aspx, .ascx, etc.). When I send along something like www.mydomain.com/anything it looks for a file or folder named "anything", and when it doesn't find one, it just drops off to the default IIS 404 handler.

That's where I took over. I changed IIS 6 to forward 404 problems to /404.aspx. I then created that page with a generic "Your file wasn't found" message in the same style as my web site.

Here's the good part: Now that IIS is sending 404's to a .NET page, the custom httpModule I created is getting fired. The request is for 404.aspx, but IIS is nice enough to also append the original URL as well. You get something like:

www.mydomain.com/404.aspx?404;http://www.mydomain.com/anything

This allows me to parse the request in the httpModule, and rewrite as needed!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文