iis-7 - IIS URL 重写 - 友好 URL : Querystring variable is repeated

标签 iis-7 url-rewriting

在我的 IIS 7 配置中,我创建了要转换的友好 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=([^=&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. 上述内容是否正确以实现我正在尝试的目标?
  2. 出于某种原因,在每次回发时我都会得到:

    http://somesite/SomeName?Name=SomeName

请注意,我已将 appendQueryString 设置为 false。

最佳答案

表单回发操作使用底层 url,而不是原始 url。

一个简单的解决方案(我相信服务器端表单操作属性仅在 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

关于iis-7 - IIS URL 重写 - 友好 URL : Querystring variable is repeated,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3207830/

相关文章:

c# - 如何设置主机头 IIS 7 出现错误?网站

asp.net - IIS7 间歇性地抛出 500 错误。谁能帮我诊断一下吗?

wordpress - 子目录中不同的lighttpd重写规则

regex - 配置nginx语言子目录

iis-7 - MSDeploy "Hangs"在 MSDeployPublish 上

wcf - IIS7自动启动时自动启动应用程序/global.asax/wcf服务

asp.net - ashx 处理程序 DELETE 请求不起作用 HTTP 405.0

java - 使用jetty如何重写Eclipse RAP应用程序的参数?

.htaccess - 子文件夹html文件中漂亮url的htaccess规则

java - JSP/Servlet 重写 URL