2009-07-10 28 views
8

我在Windows 7 RC上使用IIS 7.5。我使用IIS Url Rewrite模块来重写URL。具有URL重写模块的IIS 7.5在Postback上加倍QueryString Params

似乎一切正常,直到我通过单击按钮执行回发。然后,追加查询字符串PARAMS我重写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+Mountain+Bike

当我点击一个按钮来执行回发时,URL更改为:

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

而当URL重写,所有的查询字符串PARAMS增加一倍 - 所以,当我想这样做是为了获得当前语言:

Request.QueryString["lang"] 

我回来的值是“恩,恩”。

其他人有这些问题吗?

UPDATE:从程序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> 
+0

你可以发布你的重写规则吗?只需发布web.config中的任何内容: ... – 2009-07-21 20:10:35

+0

已更新,其中包含重写规则和产品页面的重定向规则。 – MartinHN 2009-07-24 10:53:27

回答

8

添加appendQueryString = “false” 属性来重写规则的动作元素为好。

希望这会有所帮助。

+0

工程就像一个魅力!现在我准备好了Windows 7 RTM。 – MartinHN 2009-07-27 19:55:41

0

这是IIS重写模块的安全功能。

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

在中等到高负载(超过100个连接到一个网站)中发现IIS重写模块管理应用程序池崩溃和产卵以及新进程。

+0

布鲁斯,我刚刚删除了UrlRewritting Dll,因为它迫使我在经典模式下使用app_pool。我想到IIS 7的内置会更好,更优化。你有其他建议吗?请让我知道..我很担心。 – aron 2011-05-27 02:43:37

11

我能够加入

Form.Action = Request.RawUrl; 

到Page_Load事件来解决问题。我能够离开appendQueryString =“TRUE”,到目前为止它工作正常。