IIS URL重写 - 友好的URL:查询字符串变量的值重复
问题描述:
在我的IIS 7的配置,我已经创建友好的网址转换:IIS URL重写 - 友好的URL:查询字符串变量的值重复
http://mysite/restaurant.aspx?Name=SomeName
到
http://mysite/SomeName
要做到这一点,我有规则如下:
<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=([^=&]+)$" />
</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>
- 请问上面似乎正确的政绩我正在尝试什么?
-
出于某种原因,在每一个回传,我得到:
请注意,我已经设置appendQueryString为false。
答
表单回发操作使用底层URL而不是原始URL。
一个简单的解决方案(我相信在服务器端表单action属性只适用于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