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; 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 thought the page was at


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


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

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