IIS 7.5 with URL Rewrite Module Doubles QueryString Params on Postback

一曲冷凌霜 提交于 2019-12-04 12:04:06

问题


I'm using IIS 7.5 on Windows 7 RC. I use the IIS Url Rewrite module to rewrite URLs.

Everything seems to work fine, until I perform a postback by clicking a button. It then appends the querystring params to my rewritten URL, like this:

Rewritten URL, as it appears in the browser: http://localhost/en/product/1239/Gary+Fisher+Hkek+Mountain+Bike

Without URL rewriting the URL is:

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

When I click a button to perform a postback, the URL changes to this:

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

And when the URL is rewritten, all querystring params are doubled - so when I want to get the current language by doing this:

Request.QueryString["lang"]

The value I get back is "en,en".

Is anyone else having those problems?

UPDATE: Rewrite rules from 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>

回答1:


Add the appendQueryString="false" attribute to the action element of the rewrite rule as well.

Hope this helps.




回答2:


I was able to solve the issue by adding

Form.Action = Request.RawUrl;

to the Page_Load event. I was able to leave appendQueryString="TRUE" and so far it is working properly.




回答3:


This is a security feature of the IIS Rewrite Module.

I personally prefer ISAPI Rewrite as it is much better, simpler to write rules, and has more features.

Have also found under moderate to high load (over 100 connections to a website) that the IIS Rewrite Module courses the application pool to crash and spawn and new process.



来源:https://stackoverflow.com/questions/1108473/iis-7-5-with-url-rewrite-module-doubles-querystring-params-on-postback

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!