如何在 IIS Express 下启用区分大小写?

发布于 2024-11-03 13:53:32 字数 182 浏览 5 评论 0原文

如果使用 IIS Express,我应该如何启用区分大小写的请求处理? IIS Express 中有设置吗?或者 URL 重写规则可以实现这一点吗?或者可能是包罗万象的 HTTP 处理程序来进行案例检查?

目标是在部署到 IIS 和 S3(其中 S3 区分大小写)之前,能够在本地捕获静态文件的大小写不一致问题。

谢谢

How should I go about enabling case sensitive request handling if using IIS Express? Is there a setting in IIS Express? or can a URL Rewrite rule accomplish this? or perhaps catch-all HTTP Handler to do the case check?

The goal is to be able to catch case inconsistencies locally, with respect to static files, before deployment to both IIS and S3 (where S3 is case sensitive).

Thanks

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

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

发布评论

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

评论(2

千と千尋 2024-11-10 13:53:32

IIS区分大小写......

但不区分文件。

IIS 不区分大小写是一种误称,不区分大小写的是 Windows 文件系统,而不是 IIS。如果 URL 包含文件路径,则 IIS 会询问 Windows 该文件是否存在,并且操作系统会响应,而不考虑字母大小写。在 Windows 中无法“启用”文件名区分大小写。

但对于除真实文件路径之外的文件路径,IIS 100% 区分大小写。 URL 字符的大小写会原封不动地传递到 IIS 管道。是否区分大小写取决于 Web 应用程序。但好的做法是,您不希望 /page1/PAGE1 不同。

ASP.NET 对查询字符串变量名称不区分大小写。再次强调,这不是 IIS。应用程序 (ASP.NET) 不区分大小写。

摘要

静态文件路径不区分大小写(由于 Windows 操作系统,而不是 IIS):

http://example.com/sUbdiRectoRy/FILe.aspx

但是,不参与文件路径的 URL 部分区分大小写(file.txt 之后的所有内容)。 aspx(除了“x”参数之外,因为 .aspx 是 ASP.NET 资源):

http://example.com/sUbdiRectoRy/FILe.aspx/Extra/Tail?x="query parameter"

如果应用程序区分大小写,则通过重写、HttpModule 等动态生成的 URL 也区分大小写。这通常不是最佳实践,因为这两个 URL 将引用两个单独的网页:

http://example.com/2012/01/23/blog-article
http://example.com/2012/01/23/BLOG-ARTICLE

IIS is case-sensitive...

...but not for files.

It is a misnomer that IIS is case-insensitive, it is the Windows file system that is case-insensitive, not IIS. If a URL contains a file path then IIS asks Windows if the file exists and the OS responds without regard to letter case. There is no way to "enable" case sensitivity for file names in Windows.

But for other than real file paths, IIS is 100% case-sensitive. The case of URL characters is passed to the IIS pipeline intact. It is up to the web application whether or not case-sensitivity exists. But good practice says you don't want /page1 to be different than /PAGE1.

ASP.NET is case-insensitive to query string variable names. AGAIN, this is not IIS. It is the application (ASP.NET) that is case-insensitive.

Summary

Static file paths are not case-sensitive (due to Windows OS, not IIS):

http://example.com/sUbdiRectoRy/FILe.aspx

HOWEVER, portions of the URL not participating in the file path are case-sensitive (everything after file.aspx below except for the 'x' parameter because .aspx is an ASP.NET resource):

http://example.com/sUbdiRectoRy/FILe.aspx/Extra/Tail?x="query parameter"

URLs that are dynamically generated by re-writes, HttpModules, etc. are also case-sensitive if the application is case-sensitive. This is usually not best practice as these two URLs would refer to two separate web pages:

http://example.com/2012/01/23/blog-article
http://example.com/2012/01/23/BLOG-ARTICLE
初见终念 2024-11-10 13:53:32

正如 Kevin Rice 已经指出的,这与 IIS 无关。
这都是关于文件系统、文件系统驱动程序和操作系统/asp.net。

Windows 2000+ 的默认文件系统是 NTFS,不区分大小写。
您需要的是区分大小写的文件系统,因此您应该寻找适用于 Windows 的区分大小写的文件系统驱动程序。

通常的默认 Linux 文件系统(称为 ext2/ext3/ext4)都是区分大小写的。
可以在这里找到适用于它们的 Windows 驱动程序:http://www.ext2fsd.com/

您 需要做的是将您的应用程序放在该文件系统上,并配置 IIS 以从那里启动应用程序(您可能想要双引导安装 Linux,这样您实际上在那台计算机上有一个 ext4 分区 - 请小心,如果您做错了,你的数据可能消失了)。

更让我困扰的是为什么S3文件系统区分大小写。
这是一件非常糟糕的事情,如果有人输错了你的 URL,或者搜索引擎将其小写,你会得到 404...

我可以建议您不要考虑如何让 Windows 区分大小写,而是看看如何让 S3 不区分大小写,这可能是更好的方法。

我实际上不知道该怎么做在 S3 上,因为我不知道 S3。
不过,我所知道的是 Linux(Amazon S3 可能正在使用 Linux),因此,如果您可以创建自己的文件系统,请在我的帖子底部 在这里您可以找到(已注释掉)执行此操作的方法。

简而言之,您创建一个所需大小 X 字节的 .dsk 文件(X = 计数 * 块大小)
使用不区分大小写的文件系统(vfat、jsf、hfsplus)对其进行格式化
并将其循环挂载到/mnt/whatever。

然后,将 Web 应用程序放在 /mnt/whatever 中,并配置 Web 应用程序的根目录。

请注意,如果在 JFS 中省略 -O,它将区分大小写。

apt-get install jfsutils
dd if=/dev/zero of=jfs.dsk bs=1048576 count=150
mkfs.jfs -O jfs.dsk
mkdir -p /mnt/jfs
mount /volumes/jfs.dsk /mnt/jfs -t jfs -o loop
umount /mnt/jfs/

或者像这样使用hfs-plus(最佳性能,HFS:高性能文件系统

sudo apt-get install hfsprogs
sudo modprobe hfsplus
sudo dd if=/dev/zero of=hfsplus.dsk bs=1048576 count=150
sudo mkfs.hfsplus /volumes/hfsplus.dsk
sudo mount /volumes/hfsplus.dsk /mnt/hfsplus -t hfsplus -o loop
umount /mnt/hfsplus/

此外,如果您不想(或不能)安装任何东西,vfat通常由默认值:

mkfs -T vfat /volumes/vfat.dsk

此外,Red-Hat 派生的 Linux 发行版(如 S3)不使用 apt-get,它们使用 rpm/yum。

而且,如果您希望永久安装文件系统,则需要在 /etc/fstab 中添加条目,更多内容请参见此处:
https://access.redhat.com/site/documentation/en-US/Red_Hat_Enterprise_Linux/4/html/Introduction_To_System_Administration/s2-storage-mount-fstab.html

或者您可以添加一个启动脚本在每次系统重新启动/引导时安装此特定文件系统。

As already pointed out by Kevin Rice, this has nothing to do with IIS.
This is all about the file system, the file-system driver and the operating system / asp.net.

The default file-system for Windows 2000+ is NTFS, which is case-insensitive.
What you need is a case-sensitive file system, so you should look for a file system driver for windows that is case-sensitive.

The usual default Linux file-systems (called ext2/ext3/ext4) are all case-sensitive.
And you can find a windows driver for them here: http://www.ext2fsd.com/

All you need to do is to put your application on that file-system, and configure IIS to start the application from there (you might want to dual-boot install Linux so you actually do have a ext4 partition on that computer - be careful, if you do that wrong, your data may be GONE).

What would bother me more is why the S3 file system is case-sensitive.
That is a very bad thing, if somebody mistypes your URL, or if a search-engine lowercases it, you get a 404...

May I suggest that instead of looking how you can get windows to be case-sensitive, you look how you can get S3 to become case-insensitive, that's probably the better approach.

I don't actually know how to do that on S3 since I don't know S3.
What I do know however is Linux (which Amazon S3 is probably using), so if you can make your own file system, at the bottom of my post here you find (commented out) ways of doing this.

In a nutshell, you create a .dsk file of wanted size X bytes (X = count * blocksize)
format it with a case-insensitive file-system (vfat, jsf, hfsplus)
and loopmount it to /mnt/whatever.

Then you put your web application in /mnt/whatever, and configure the root directory for the web-application to be there.

Note that if you omit -O in JFS, it will be case-sensitive.

apt-get install jfsutils
dd if=/dev/zero of=jfs.dsk bs=1048576 count=150
mkfs.jfs -O jfs.dsk
mkdir -p /mnt/jfs
mount /volumes/jfs.dsk /mnt/jfs -t jfs -o loop
umount /mnt/jfs/

or like this with hfs-plus (best performance, HFS: high-performance file-system)

sudo apt-get install hfsprogs
sudo modprobe hfsplus
sudo dd if=/dev/zero of=hfsplus.dsk bs=1048576 count=150
sudo mkfs.hfsplus /volumes/hfsplus.dsk
sudo mount /volumes/hfsplus.dsk /mnt/hfsplus -t hfsplus -o loop
umount /mnt/hfsplus/

Also, if you don't want to (or can't) install anything, vfat is usually installed by default:

mkfs -T vfat /volumes/vfat.dsk

Also, Red-Hat derived Distributions of Linux (like S3) don't use apt-get, they use rpm/yum.

And, if you want the filesystem to be permanently mounted, you need to add the entry to /etc/fstab more on it here:
https://access.redhat.com/site/documentation/en-US/Red_Hat_Enterprise_Linux/4/html/Introduction_To_System_Administration/s2-storage-mount-fstab.html

or you can add a startup script that mounts this particular file system on every system restart/boot.

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