jQuery not working in IE using URL Rewrite Module (IIS)

jQuery not working in IE using URL Rewrite Module (IIS)

I observed that using Internet Explorer 9 to show a jQuery-page some times the loading gets broken when using outboundRules in Web.config.

 

THE SETUP

To reproduce the behavior on a Windows 7 Professional machine (or use attachment):

  1. Create a Directory "C:Temp/Test"
  2. Create two .txt-files, copy and paste the code below
  3. Rename it to default.aspx and web.config.
    Alternatively use Visual Studio to create these 2 files
  4. Download jQuery 1.8.1-min and safe it into the directoy
    (although it makes no difference if you use an online resource like
    https://developers.google.com/speed/libraries/devguide#jquery)

  5. IIS 7.5: Create a new website using C:/Temp/Test and let's say e.g. port 20000 for binding
  6. run it in Internet Explorer using http://localhost:20000

Now you can see that the link is perfectly rewritten when moving the mouse over it.
You can even click the link hundred times, no problem.

 

THE PROBLEM

Now when you click F5 several times the jquery stops working and Internet Explorer gives an error like:

row 9: error "$" is undefined
(thats the row with $(document).ready(function ())

 

points of interests:

  • the same error occurs when hosting the side on an Windows 2008 R2 Enterprise Server
  • using Chrome everything works perfectly, even if you refresh the page
  • removing the rewrite section in web.config everything works perfectly in Internet Explorer, too

Any ideas how to solve this?

regards,
Foizman



Listing 1 (default.aspx):

<%@ Page Language="vb" AutoEventWireup="false" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Test</title>
<script src="jquery-1.8.1.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
});
</script>
</head>
<body>
<form id="form1" runat="server">
<p>
Move Mouse over the link to show the rewriting of the Url</p>
<p>
<a href="default.aspx?id=123">Reload</a></p>
<p>
Now using Internet Explorer press F5 several times...</p>
</form>
</body>
</html>






















Listing 2 (web.config):

<?xml version="1.0"?>
<configuration>
<system.webServer>
<rewrite>
<outboundRules>
<remove name="Test" />
<rule name="Test">
<match filterByTags="A" pattern="^default\.aspx\?ID=(.+)"/>
<action type="Rewrite" value="default.aspx?rewritten({R:1})"/>
</rule>
</outboundRules>
</rewrite>
</system.webServer>
<system.web>
<compilation debug="true"/>
</system.web>
</configuration>