URL Rewrite stops AJAX from working. PLEASE HELP!

Discussion in 'Site Programming, Development and Design' started by jason, May 22, 2010.

  1. Please help, i have been working on my site for a long time and just implemented a rule on IIS under URL Rewrite. This causes all the Ajax controls to act wierd or not at all. specifically update panels, buttons, and image buttons.

    I remove the rule and all goes back to working normally. i need the URL rewrite, in my case it is www.host.com/bands.aspx?band=bandname to www.host.com/band

    Please help... I cant believe that AJAX doesnt work with URL Rewrite but have scoured the internet and forums for help for days now.

  2. Ray


    Whats the error message our getting? Do you have a URL we can look at. I suggest you upload a test script in a subfolder and set it as an application folder and setup the URL rewrite in that subfolder so we can see what is going on.
  3. Hello Ray, thanks for the reply!!

    i did some more searching in this forum and seems this issue has come up before .. here


    there is a post in here that states you can not create the url rewrite on the root directory and that you must have a directory between in order for ajax to continue working. for example:

    url rewrite to: www.bandsUK.com/U2 will break all ajax
    url rewrite to: www.bandsUK.com/bands/U2 will keep ajax working.

    i tested this and yes it works. I really wanted the easiest url but can live with this if its the only solution.

    However, because i use master pages, the links on the master pages dont work on the pages that are in the subfolder that url rewriting is on. arrggg! now i might need two masterpages, one for first level and one for second level.

    BTW, Ray, there is no error messages, the ajax simply does not work, it is completly ignored.

    any thoughts? any one?

    thanks, jason
    Last edited by a moderator: Oct 14, 2015
  4. Ray


    I'm not sure if we should conclude that this issue is similar to one of the posts on the forum. First off can your AJAX application work without the URL Rewrite rule? Do you have a link I can look at?
  5. Ray,

    Yes, everything works great when there is no URL Rewrite. As soon as i put a URL rewrite on the root, all the AJAX controls stop working. There is no error message, they are just ignored. This is the URL Rewrite i want: http://www.bands.com/bands.aspx?band=U2 rewritten to http://www.bands.com/u2

    I created a test page at http://hotshotb.w02.Winhost.com/testajax/testajax.aspx and the update panel works because when you click submit the page does not refresh, just the panel. There is a URL Rewrite in place but at a folder below root: http://hotshotb.w02.Winhost.com/testajax/parm and this keeps things working.

    Perhaps it is in the settings of the URL Rewrite? I can send a screen shot of my setup. I am a newbie at URL Rewrites and server settings are a little our of my scope. However, it seems quite straight forward.

    What tests can i run further with you? thanks a lot! jason
    Last edited by a moderator: Oct 14, 2015
  6. Ray


  7. thanks Ray for the article. it was good and clearly shows there are problems with AJAX and URL Rewrite.

    I tried both suggestions about replacing the raw url in the form1.action tag and adding a condition on the rewrite to avoid rewriting the axd files.

    This stopped the errors when running ajax and all controls work fine, even now when the url rewrite is on the route folder. However, the url rewrite does not work. You type in the friendly URL and server produces page can not be found error. When I remove the axd condition the url rewrite works but then the AJAX controls no longer function. I think this is a little closer though..

    I will continue to play with the settings. here is the condition statement

    Last edited by a moderator: Oct 14, 2015
  8. Ray


    Try creating a couple of different rules instead of having several filters under one rule.
  9. I finally figured this issue out. I moved hosting services. Not what you want to hear at Winhost but hey, i tried another hosting service, did the exact same thing and voila, the url rewrite worked perfectly first time. Here is what I wanted to do:

    have a url like http://www.mysite.com/band.aspx?band=u2

    be written to http://www.mysite.com/u2

    cool, huh. and here is the code i put in the webconfig file:

    <rule name="RewriteUserFriendlyURL1" stopProcessing="true">
    <match url="^([^/]+)/?$" />
    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
    <!-- The following condition prevents rule from rewriting requests to .axd files -->
    <add input="{URL}" negate="true" pattern="\.axd$" />
    <action type="Rewrite" url="band.aspx?band={R:1}" />

    This might help someone. cheers.
    Last edited by a moderator: Oct 14, 2015
  10. Ray


    This rule should also work on the Winhost servers.
    Last edited by a moderator: Oct 14, 2015
  11. Yeah, there's nothing server-side that would cause a rewrite rule to work differently on one IIS server compared to another.

    You know, unless one of them is magic!
  12. fixed

    Great job Jason! Adding an extra condition to my existing rule fixed the problem. I now stand corrected when I previously said Winhost does not support AJAX when hosting multiple web sites within one Winhost account. See my previous post which you referenced for the solution.
    Last edited by a moderator: Oct 14, 2015
  13. segiles i tried the same thing with multiple domains but this brings all the sites down to a server error which happenes to be redirecting all the sites at the one time:


    rather than doing them seperately if that makes sense can you please copy and paste all the rules you have so i can see what i have done wrong :)?

Share This Page