【问题标题】:Postback after button click in ASP.NET causes URL to change在 ASP.NET 中单击按钮后的回发导致 URL 更改
【发布时间】:2013-05-23 09:34:54
【问题描述】:

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

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

被改写为:

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

现在,index.aspx 页面上有一个linkbutton(点击事件中没有任何代码)。当我单击按钮时,停留在 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>

【问题讨论】:

  • 如果您的代码和重写配置,您能否展示使用相关部分?
  • 配置文件中的重写规则是这样的:
  • 这个链接按钮是怎么生成的?

标签: asp.net url-rewriting


【解决方案1】:

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

Form1.Action = Request.RawUrl;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-09-28
    • 2010-10-23
    • 1970-01-01
    • 2015-06-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-10
    相关资源
    最近更新 更多