2 Answers
2

I just tested it out my solution together with XPath solution and it's not behaving as expected. It seems that there is no way of controlling the order of entries. Thanks Per for his input!

Update 2

Could you please try using HttpApplication instead of HttpContext because HttpApplication defines the methods, properties, and events common to all application objects within an ASP.NET application. See more

Finally I ended up with a different approach for my custom error pages.

Because it is not possible to control the order of elements in web.config programmatically (which sucks so much!) and editing manually is no option, I gave up the approach with a HttpModule and manipulating web.config.

Additionally I added a custom 404.html file to the solution in the mapped LAYOUTS\1033 folder and registered that file for the application in the same feature receiver (see code below). The 404.html does a redirect to a .aspx-File. The aspx has a control which renders the content internationalized. You can also just set the static html for 404 errors. The reason for the redirect was internationalization.

One additional pitfall with the .html file and non-IE-browsers was for me the problem described here (because I copied the standard SP 404.html for a starting point):