IIS7:带句点的 URL 重写

发布于 2024-10-18 21:53:49 字数 272 浏览 2 评论 0原文

我使用的是 SEO 友好的 URL,并且可以通过将 aspnet_isapi.dll 映射到所有 URL,使用 ASP.NET 处理其中的大部分。 (我在 IIS 中设置了一个处理程序映射,该映射对所有路径使用 dll。(path = *))

但是,当“子文件夹”的最后一个字符是句点时,这似乎不起作用。例如,我的 URL 为 /brakes/ABS/,这不会触发映射。所以我最终会遇到此类 URL 的 404。有谁知道我应该如何设置映射来触发这个? (我已经尝试过*。但这也不起作用。)

I'm using SEO-friendly URLs, and I can process most of them with ASP.NET, by mapping aspnet_isapi.dll to all URLs. (I set up an Handler Mapping in IIS that uses the dll for all paths. (path = *))

However, that doesn't seem to work when the last character of a "subfolder" is a period. E.g., I have a URL of /brakes/A.B.S./, and that won't trigger the mapping. So I end up with 404s for such URLs. Does anybody know how I should setup the mapping to trigger this? (I've tried *. and that doesn't work either.)

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

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

发布评论

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

评论(4

千年*琉璃梦 2024-10-25 21:53:49

尝试在 web.config 中更改此设置:

<httpRuntime relaxedUrlToFileSystemMapping="true" />

http ://haacked.com/archive/2010/04/29/allowing-reserved-filenames-in-URLs.aspx

Try changing this setting in your web.config:

<httpRuntime relaxedUrlToFileSystemMapping="true" />

http://haacked.com/archive/2010/04/29/allowing-reserved-filenames-in-URLs.aspx

月下客 2024-10-25 21:53:49

正如 Matthew 已经指出的那样,这在 .NET 4.0 中是可以解决的,但在 .NET 2.0 中则不行。问题在于底层系统:Microsoft 禁止名称以点(或空格)结尾,因为 Windows 资源管理器无法处理它们(但是底层 NTFS 系统可以处理它们) 。

原因是什么

在内部,对于 .NET 2.0 和 .NET 4.0 来说都是如此,Web 请求在某个时刻被传递到方法 IsSuspiciousPhysicalPath。除其他外,此方法调用标准 API 以根据给定路径创建“官方”路径。它不会创建这条路径。然后它将正确的路径与给定的路径进行比较。如果它们不同(即,如果给定路径不存在于正确的路径中),则认为是可疑的。

您可以自己尝试一下:使用 File.CreateFile 创建文件“test.txt....”。这将成功,但生成的文件是“test.txt”。在上面的场景中,给定的文件“text.txt...”不适合创建的文件,因此它是可疑的,甚至永远不会到达网络请求处理程序。

即使基本 IIS 设置中的 404 处理程序也无法在这里工作!

牵强的解决方法

我在许多设置中使用了多年的解决方法(出于与此问题无关的原因):在 IIS 前面安装 Apache 并将其配置为代理。这相对容易设置(互联网上丢失了示例),并且可以充当处理此类“非法请求”的缓冲区,将它们重写为 IIS可以处理的内容。

但从 .NET 2.0 迁移到 .NET 4.0 可能更容易

As Matthew already pointed out, this is resolvable in .NET 4.0, but not in .NET 2.0. The problem lies in the underlying system: Microsoft forbids names to end with a dot (or a space, for that matter), because Windows Explorer cannot handle them (the underlying NTFS system can handle them, however).

What's the cause

Internally, and this is true for .NET 2.0 and .NET 4.0, a web request is passed, at some point, to the method IsSuspiciousPhysicalPath. Among other things, this method calls a standard API to create an "official" path based on the path given. It doesn't create this path. Then it compares this correct path with the given path. If they are different (i.e., if the given path does not exist in the corrected path) it is considered suspicious.

You can try this yourself: use File.CreateFile to create the file "test.txt....". This will succeed, but the resulting file is "test.txt". In the scenario above, the given file "text.txt...." does not fit the created file, hence it is suspicious and never even reaches the web request handler.

Even a 404-handler in the base IIS settings won't work here!

A far-fetched workaround

A workaround which I've used for years in many setups (for reasons not related to this issue): install Apache in front of IIS and configure it for proxying. That's relatively easy to setup (lost of examples on the internet) and this can act as a buffer for handling these kind of "illegal requests", rewriting them to something IIS can handle.

But it is probably easier to simply move from .NET 2.0 to .NET 4.0

刘备忘录 2024-10-25 21:53:49

我正在使用 Web API 属性路由

所选答案对我不起作用,它只是部分解决方案。

为了确保 Web API 得到第一个破解,您不仅需要让

<configuration>
  <system.web>
    <httpRuntime relaxedUrlToFileSystemMapping="true"/>
  </system.web>
</configuration>

您还需要让

<system.webServer>
  <modules runAllManagedModulesForAllRequests="true"></modules>
</system.webServer>

我在这个博客中找到答案:

允许在 ASP.NET MVC 应用程序中使用点(特别是 IIS 7+)

I'm using Web API attribute routing

The selected answer did not work for me, it is only a partial solution.

to make sure the Web API gets the first crack at it, not only will you need to have

<configuration>
  <system.web>
    <httpRuntime relaxedUrlToFileSystemMapping="true"/>
  </system.web>
</configuration>

you also need to have

<system.webServer>
  <modules runAllManagedModulesForAllRequests="true"></modules>
</system.webServer>

I found the answer here at this blog:

ALLOW A DOT IN ASP.NET MVC APPLICATION (SPECIFICALLY IIS 7+)

暮倦 2024-10-25 21:53:49

就我而言,我无法使用 URL 重写来完成此操作,而还有另一个原因,即 URL 扫描。

我在文本编辑器中打开 windows\system32\inetsrv\urlscan\urlscan.ini 并通过将其值更改为 1 来启用 AllowDotInPath

In my case, I couldn't do it using the URL Rewrite while there was another reason which is the URL Scan.

I opened windows\system32\inetsrv\urlscan\urlscan.ini in a text editor and enabled AllowDotInPath by changing its value to 1

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