【发布时间】:2013-06-23 07:28:19
【问题描述】:
我对 Url 重写和重定向的理解是(请指出我的错误假设)
通过对 url 使用“重定向”选项
http://localhost/Search/VehicleDetails.aspx?id=2改造它 进入http://localhost/Search/2/VehicleDetails.aspx,当客户端 浏览http://localhost/Search/VehicleDetails.aspx?id=2和我们的 将规则更改重定向到http://localhost/Search/2/VehicleDetails.aspx,服务器尝试 在/Search/2文件夹中找到 VehicleDetails.aspx 页面。但是通过对 url 使用“重写”选项
http://localhost/Search/VehicleDetails.aspx?id=2改造它 进入http://localhost/Search/2/VehicleDetails.aspx,当客户端 浏览http://localhost/Search/VehicleDetails.aspx?id=2,客户端 浏览器显示http://localhost/Search/2/VehicleDetails.aspx,但是 在服务器内部请求是在 VehicleDetails.aspx 页面中进行的 搜索目录,不在 /Search/2 的 VehicleDetails.aspx 中 目录...
我的问题是,我尝试按照规则重写 url
<rewrite>
<rules>
<rule name="Search" stopProcessing="true">
<match url="^.*(?:Search/VehicleDetails.aspx).*$" />
<conditions>
<add input="{QUERY_STRING}" pattern="id=(\d+)" />
</conditions>
<action type="Rewrite" url="/Search/{C:1}/VehicleDetails.aspx" redirectType="Permanent" appendQueryString="false" />
</rule>
</rules>
</rewrite>
它重定向到带有HTTP 404.(The resource cannot be found.) 的/Search/2/VehicleDetails.aspx 页面。我希望客户端浏览器显示http://localhost/Search/2/VehicleDetails.aspx,但在/Search/VehicleDetails.aspx 上发出请求..
还有我如何获得 id 的值(在本例中为 2)为 url 像
http://localhost/Search/2/VehicleDetails.aspx by Request.QueryString["id"]??
【问题讨论】:
标签: c# asp.net redirect iis-7 url-rewriting