Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

URL rewriting page load loops

I am using Intelligencia UrlRewriter to apply URL Rewriting.

I took page1.aspx and used the OnClick event of a button and did a Response.Redirect to page2.aspx. Everything works fine if I test with these two sample pages.

Then I applied some styles and javascript to page2.aspx. When I click the same button on page1.aspx and put a break point on page2.aspx.cs page_load function, what I observed is that page_load function is looped for multiple times and it loops and loads all the database calls multiple times.

Applying IsPostback didn't help. Then I removed the CSS and JS then everything is fine.Need answer why this page_load function repeats multiple times.

like image 412
harry Avatar asked Dec 27 '25 21:12

harry


1 Answers

I had this problem too. Like the others have touched on, it can be caused by relative paths inside your page.

I was rewriting:

domain.com/article/12345/title-here 

To become:

domain.com/article.aspx?ID=12345

Problem was, there were 2 images with relative paths:

  EG. images/fb.jpg
      images/tw.jpg

By logging the value in Request.RawUrl.ToString(), I was able to see that the browser was requesting following images:

 domain.com/article/12345/images/fb.jpg

 domain.com/article/12345/images/tw.jpg

Although these files don't exist, the URL still satisfied the redirect rule.

Thus, rewriting the URL to:

domain.com/article.aspx?ID=12345

Which explains why my page loaded three times. Once for the HTML, and once for each image.

Changed the image src values to an absolute path and the problem was solved.

like image 65
Eric Avatar answered Dec 30 '25 16:12

Eric



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!