我在 Windows 7 RC 上使用 IIS 7.5。我使用 IIS Url Rewrite 模块来重写 URL。

一切似乎都工作正常,直到我通过单击按钮执行回发。然后它将查询字符串参数附加到我重写的 URL 中,如下所示:

重写的 URL,如浏览器中显示的那样:http://localhost/en/product/1239/Gary+Fisher+Hkek+Mountain+Bike

如果没有 URL 重写,则 URL 为:

http://localhost/product.aspx?lang=en&id=1239&title=Gary+Fisher+Hkek+山地+自行车

当我单击按钮执行回发时,URL 更改为:

http://localhost/en/product/1239/Gary+Fisher+Hkek+Mountain+Bike?lang=en&id=1239&title=Gary+Fisher+Hkek+Mountain+Bike

当 URL 被重写时,所有查询字符串参数都会加倍 - 所以当我想通过这样做来获取当前语言时:

Request.QueryString["lang"]

我得到的值是“en,en”。

还有其他人有这些问题吗?

更新:从 Web.Config 重写规则

<rule name="RedirectProductPageUrls" stopProcessing="true">
    <match url="^product\.aspx$" />
    <conditions logicalGrouping="MatchAll">
        <add input="{REQUEST_METHOD}" negate="true" pattern="^POST$" />
        <add input="{QUERY_STRING}" pattern="^lang=([^=&amp;]+)&amp;id=([^=&amp;]+)&amp;title=([^=&amp;]+)$" />
    </conditions>
    <action type="Redirect" url="{C:1}/products/{C:2}/{C:3}" appendQueryString="false" redirectType="Permanent" />
</rule>
<rule name="RewriteProductPageUrls" stopProcessing="true">
    <match url="^([^/]+)/product/([^/]+)/([^/]+)/?$" />
    <conditions logicalGrouping="MatchAll">
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
    </conditions>
    <action type="Rewrite" url="product.aspx?lang={R:1}&amp;id={R:2}&amp;title={R:3}" />
</rule>
有帮助吗?

解决方案

appendQueryString =“false”属性添加到重写规则的操作元件,以及

希望这有助于。

其他提示

我能够通过添加,以便解决问题

Form.Action = Request.RawUrl;

到Page_Load事件。我能离开appendQueryString =“TRUE”,至今它是否工作正常。

这是IIS重写模块的安全特征。

我个人更喜欢ISAPI重写,因为它是更好的,更简单的编写规则,并具有更多的功能。

让下也中等至高负载发现(超过100个连接到一个网站)的IIS重写模块课程的应用程序池崩溃和产卵和新的进程。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top