在ASP.NET中单击按钮后回发会导致URL更改

时间:2013-05-23 09:34:54

标签: asp.net url-rewriting

我有一个ASP.NET网站,它使用URL重写规则来提供有意义的URL。网址:

www.example.com/folder/reports/{name}

被重写为:

www.example.com/index.aspx?Title={name}

现在,linkbutton页面上有一个index.aspx(点击事件中没有任何代码)。当我点击按钮时,保留URL:www.example.com/folder/reports/{name},而不是在回发后留在同一个URL,它会转到URL: www.example.com/folder/reports/{name}?Title={name}因此会显示错误消息。

有人可以解释一下为什么按钮点击会导致这个错误的网址,即使页面上的刷新让我处于同一个页面吗?

以下是我的web.config规则配置:

<rule name="Rewrite to page">
  <match url="(.*)/reports/(.*)" />
  <conditions>
    <add input="{REQUEST_FILENAME}" pattern="(.*(\.html|\.htm|\.aspx)$)" negate="true" />
  </conditions>
  <action type="Rewrite" url="/index.aspx?Title={R:2}" />
</rule>

1 个答案:

答案 0 :(得分:3)

我能够通过在母版页的Page_Load事件中添加这一行来解决这个问题:(其中'Form1'是母版页中使用的asp格式)

Form1.Action = Request.RawUrl;