我可以在 URL 中使用逗号吗? [英] Can I use commas in a URL?

查看:30
本文介绍了我可以在 URL 中使用逗号吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通常使用 URL 重写来将内容 ID 传递到我的网站,所以这个

I typically use URL rewriting to pass content IDs to my website, so this

 Foo.1.aspx 

重写为

 Foo.aspx?id=1

对于特定的应用程序,我需要将多个 ID 传递到单个页面,因此我重写了一些内容以接受这一点:

For a specific application I need to pass in multiple IDs to a single page, so I've rewritten things to accept this:

 Foo.1,2,3,4,5.aspx

这在 Cassini(Visual Studio 的内置临时 Web 服务器)中运行良好,但是当我在运行 IIS 的实时服务器上尝试时,它给我Internet Explorer 无法显示网页".这是 IIS 限制吗?我应该只使用破折号或下划线而不是逗号吗?

This works fine in Cassini (the built-in ad hoc web server for Visual Studio) but gives me "Internet Explorer cannot display the webpage" when I try it on a live server running IIS. Is this an IIS limitation? Should I just use dashes or underscores instead of commas?

推荐答案

我记得默认情况下,Url Routing 首先检查文件是否存在,并且文件名中的逗号是不合法的,这就是为什么会出现错误的原因.IIS 可能有遗留代码,这些代码会在请求到达 asp.net 进行处理之前中止请求.

I recall that Url Routing by default first checks to see if the file exists, and commas are not legal in filenames, which is parhaps why you are getting errors. IIS may have legacy code that aborts the request before it can get to asp.net for processing.

Scott Hanselman 的博文 对此进行了一些讨论,可能与您有关.

Scott Hanselman's blog post talks a bit about this and may be relevant for you.

作为一般性评论:网址重写通常用于使网址友好且易于记忆.

As general comment: Url rewriting is typically used to make a url friendly and easy to remember.

~/page.aspx?id=1,2,3,4~/page/1-2-3-4.aspx 不差也不好> : 两者都很难使用,为什么还要付出额外的努力呢?避免仅仅因为可以创建新的 url 表单.用户、帮助台和其他开发人员只会感到困惑.

~/page.aspx?id=1,2,3,4 is neither worse nor better than ~/page/1-2-3-4.aspx : both are difficult to use so why go through the extra effort? Avoid creating new url forms just because you can. Users, help desk, and other developers will just be confused.

最好利用 URL 重写来进行转换

Url rewriting is best utilized to transform

~/products/view.aspx?id=1
~/products/category.aspx?type=beverage

进入

~/products/view/1
~/products/category/beverage

这篇关于我可以在 URL 中使用逗号吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆