开发者

IIS URL Rewriting - Friendly URL: Querystring variable is repeated

In my IIS 7 configuration, I have created friendly URLs to convert:

http://mysite/restaurant.aspx?Name=SomeName 
开发者_C百科

to

http://mysite/SomeName

To do this, I have the following rules:

<rule name="RedirectUserFriendlyURL1" enabled="true" stopProcessing="true">
  <match url="^Restaurant\.aspx$" />
    <conditions>
      <add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
      <add input="{QUERY_STRING}" pattern="^Name=([^=&amp;]+)$" />
    </conditions>
  <action type="Redirect" url="{C:1}" appendQueryString="false" />
</rule>

<rule name="RewriteUserFriendlyURL1" enabled="true" stopProcessing="false">
  <match url="^([^/]+)/?$" />
    <conditions>
      <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
      <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
      <add input="{REQUEST_FILENAME}" pattern=".aspx" negate="true" />
    </conditions>
  <action type="Rewrite" url="Restaurant.aspx?Name={R:1}" appendQueryString="false" />
</rule>
  1. Does the above seem correct to achieve what I'm trying?
  2. For some reason, on every postback I get:

    http://somesite/SomeName?Name=SomeName

Note that I have set appendQueryString to false.


The form postback action uses the underlying url, not the raw url.

A simple solution (I believe the server side form action property is only available in 3.5+):

protected void Page_Load(object sender, EventArgs e)
{
    if ( !String.IsNullOrEmpty(Request.ServerVariables["HTTP_X_ORIGINAL_URL"]) )
    {
        form1.Action = Request.ServerVariables["HTTP_X_ORIGINAL_URL"];
    }
}

http://blogs.iis.net/ruslany/archive/2008/10/23/asp-net-postbacks-and-url-rewriting.aspx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜