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

Nis*_*ddy 3 asp.net url-rewriting

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

www.example.com/folder/reports/{name}
Run Code Online (Sandbox Code Playgroud)

改写为:

www.example.com/index.aspx?Title={name}
Run Code Online (Sandbox Code Playgroud)

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

有人可以解释为什么单击按钮会导致此错误的 URL,即使页面上的刷新使我保持在同一页面上?

这是我的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>
Run Code Online (Sandbox Code Playgroud)

Nis*_*ddy 5

通过在母版页的 Page_Load 事件中添加这一行,我能够清除这个问题:(其中“Form1”是母版页中使用的 asp 表单)

Form1.Action = Request.RawUrl;
Run Code Online (Sandbox Code Playgroud)