1

我有一个自定义网站,我正在使用自定义引擎自动重写 url。只要页面 url 不以 .htm 或 .html 之类的结尾,重写就可以正常工作。对于这些页面,它直接进入 iis 404 页面,而不是先访问我的重写引擎。

我在该网站的 IIS6 配置的“主目录”部分有 * 通配符处理程序,但这些 url 似乎被它忽略了(尽管 css、jpg、js 等内容被发送到我的 web 中的 url 处理程序项目)。如何设置 IIS6 以强制将这些 url 发送到处理程序,同时在页面正常存在的情况下仍为页面提供服务?

处理程序基本上是这样做的

if (!File.Exists(Request.Path))
{
    doMyRewriting();
}

我必须假设如果请求的文件不存在,则使用这样的块(例如,真正的块做一些其他的东西来格式化Request.Path以适合所有内容)应该运行“doMyRewriting()”它将正常提供页面。我弄错了吗?

如果我专门告诉 IIS 将 .htm 和 .html 页面通过 .NET 处理程序发送到 .NET 处理程序,则重写工作,但如果页面实际上在那里,它将不会提供它。

任何帮助将不胜感激。

提前致谢!

4

3 回答 3

3

不知道您是否可以或想要这样做,但是您可以使用 Ionics Isapi url 重写器。

http://www.codeplex.com/IIRF

基本上安装它,然后设置一个规则来删除 .html ,这样它就会碰到你的重写引擎。我在 IIS 6 上使用它和我的几个博客。

于 2008-12-31T17:47:24.497 回答
1

我认为如果您让 IIS 将所有请求发送到 .NET 和您的处理程序,那么您的处理程序将需要检测页面是否存在并提供它而不是重写。

UrlRewriting.NET 可以选择执行此操作 - 您可能想查看他们的代码以了解他们如何处理这种情况。

于 2008-12-31T17:28:11.353 回答
1

In my opinion, rewriting URLs with IIS 6 is best handled with an ISAPI filter written as unmanaged native code. Otherwise, you run into the issues you've mentioned - having to map all extensions to ASP.Net and losing the ability for simple file handling. With an ISAPI filter, you can choose to not rewrite some URLs and let IIS handle them as normal.

To get started, I suggest reading the ISAPI Filter Overview on MSDN.

If your filter absolutely needs the .Net framework runtime, it is possible to write a small ISAPI filter shell that hosts the CLR and forwards the requests to some managed code. The Filter.Net Framework takes this approach and may be suitable for your needs. There is the small drawback to this approach in that you will have to use the same .Net version as any ASP.Net applications that are run in the main IIS process.

于 2009-01-03T06:43:24.950 回答