Sep 12 2009

Prevent URL Rewriting of Requests for ASP.NET-WebResources.axd

Category: Ajax | ASP.NETLatif @ 14:50

Hi again,

 WebResources.axd is created by ASP.NET for performing AJAX processes in the page. İn Addition, there is no such file on the web server due to the fact that ASP.NET produce the content dynamically when WebResources.axd is requested.


If you want to see the content of WebResources.axd, you have to run it on browser. Script path is in the page source code like below,


<script src="/WebResource.axd?d=7OCAQ3R3VOQC0D4ciLQ5OCpSc8_wxlQ0C-KYhGZ-_ag1&amp;t=633566872339565967" type="text/javascript"></script>


İf you are using Url Rewring, URL rewrite rule may accidentally make the requests to WebResources.axd and this will break your application.


Anyway, in order to prevent URL Rewriting of Requests for ASP.NET Web Resources(.axd) and other type of files such as .xml,.js,.css , you should add rule to web.config.


     <rewrite url="^(/.+(\.gif|\.png|\.jpg|\.ico|\.xml|\.pdf|\.axd|\.css|\.js)(\?.+)?)$" to="$1" processing="stop" />

     <rewrite url="/([0-9]{6})(.*)/(.*)-(.*)" to="~/Detail.aspx?aid=$1" />



The problem can be easily prevented by this rule.


Have a good time...