Monday, June 14, 2010

AJAX and URL Rewrite: Sys is undefined Issue

I created a website on a subfolder of my domain, and later moved it to a subdomain as its own application. Oddly, after I did this, I saw an issue pop up wherein javascript errors were thrown every time I opened a page that:
Message: Syntax error
Line: 3
Char: 1
Code: 0
URI: http://(domain)/WebResource.axd?d=3sB1WgLxUgrovkMyz-aqWw4&t=633626442871064790

... along with 2 errors for the ScriptResource.axd file and 2 instances of a 'Sys' is undefined error.
After some research, I found that this is caused by the combination of AJAX and URL Rewrite. I'm not sure if it is specific to GoDaddy hosting, or global. It's strange that it didn't surface until I moved my project. Regardless, I have found a solution.

The major problem is that my application is not recognizing the WebResource.axd and ScriptResource.axd as files; therefore tying to rewrite their urls using them as keywords.

My current URL Rewrite structure looks like this:
<rewrite>
<rules>
<rule name="RewriteCheck" stopProcessing="true">
<match url="^(.+)$" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}"
matchType="IsFile"
negate="true" />
<add input="{REQUEST_FILENAME}"
matchType="IsDirectory"
negate="true" />
</conditions>
<action type="Rewrite" url="UserProfile.aspx?key={R:0}" />
</rule>
</rules>
</rewrite>


I'm already checking for files and directories, but now I need to check for these .axd files before casting a url into the rewriter. Therefore, I'll use the bounce URLs off a pattern *.axd to negate them from being processed by the Rewrite function.
<rewrite>
<rules>
<rule name="RewriteCheck" stopProcessing="true">
<match url="^(.+)$" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}"
matchType="IsFile"
negate="true" />
<add input="{REQUEST_FILENAME}"
matchType="IsDirectory"
negate="true" />
<add input="{URL}"
pattern=".*.axd$"
negate="true" />
</conditions>
<action type="Rewrite" url="UserProfile.aspx?key={R:0}" />
</rule>
</rules>
</rewrite>


I re-ran my application and every worked like a charm!

1 comments:

Unknown said...

GoDaddy have not <outboundRules> rules

Post a Comment