ASP.net aspx pages posting back to the wrong URL when using Server Rewrite


Had a problem today working on a new phase of one of our existing sites (a problem which I’m sure I came up against on another site and fixed a few years ago…) – we just added server rewrite with a whole new URL structure like so;

www.site.com/ group name/ series name/ book.htm

This allows the user to chop off a folder and get back to the relevant listing page- pretty standard stuff now days.  So this introduces a bunch of virtual folders.  All the sites resources were set to use absolute paths and everything was loading in and rendering fine, but the page crashed every time I click the “Add to cart” button– bit of a show stopper.

This was because dot net isn’t aware of the rewrite- so while they hit the site on a url like;

childrens-books/beast-quest/book1.htm

asp.net thought the page was at

book-details.aspx?id=9780123456789&catId=1&seriesId=2

so did a post back to that page, relative to the current folder, giving me;

childrens-books/beast-quest/book-details.aspx?id=9780123456789&catId=1&seriesId=2

trying to reference the physical file (which existed at the root level) from the context of a folder which doesn’t really exist.  The fix is easy (once you find it!) – for this site the main asp.net form tag was in the masterpage so I just added the following to the Page_Load of my master page;

form1.Action = Request.RawUrl;

Thanks to Ruslan Yakushev’s post on IIS.net

  1. No comments yet.
(will not be published)