Nishanth Reddy
Nishanth Reddy

Reputation: 609

Postback after button click in ASP.NET causes URL to change

I have an ASP.NET website that uses URL rewrite rules for provides meaningful URLs. The URL:

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

is rewritten to:

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

Now, there is a linkbutton on the index.aspx page (doesn't have any code in the click event). When I click on the button, staying on the URL: www.example.com/folder/reports/{name}, instead of staying at the same URL after the post-back, it goes to the URL: www.example.com/folder/reports/{name}?Title={name} and thus shows an error message.

Can someone please explain why the button-click is causing this wrong URL, even though a refresh on the page keeps me at the same page?

Here is my web.config rules configuration:

<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>

Upvotes: 3

Views: 2439

Answers (1)

Nishanth Reddy
Nishanth Reddy

Reputation: 609

I was able to clear this problem, by adding this line in the Page_Load event of the master-page:(where 'Form1' is the asp form used in the master-page)

Form1.Action = Request.RawUrl;

Upvotes: 5

Related Questions