URL Rewriting Causes ASP.NET AJAX Error

Discussion in 'Site Programming, Development and Design' started by gabriel93, Dec 23, 2009.

  1. Hey,

    I am trying to use ASP.NET AJAX however I keep running into an error because I am using url rewriting which is stuffing up the path for the script resources.

    On my page http://www.gabrielsadaka.com.au/mail/mail.aspx I am getting these errors:

    Webpage error details

    Message: ASP.NET Ajax client-side framework failed to load.
    Line: 90
    Char: 34
    Code: 0
    URI: http://gabrielsadaka.com.au/mail/mail.aspx


    Message: 'Sys' is undefined
    Line: 101
    Char: 1
    Code: 0
    URI: http://gabrielsadaka.com.au/mail/mail.aspx


    Message: 'Sys' is undefined
    Line: 142
    Char: 1
    Code: 0
    URI: http://gabrielsadaka.com.au/mail/mail.aspx

    If you view the source you will be able to see that the scripts referred to are actually in directories which don't exist. e.g.="/gabrielsadaka/mail/WebResource.axd?d=gg3vhF1my5qxLjS7Ox6lkg2&t=633833943844060961"

    Because of the url rewriting the script is being directed to www.gabrielsadaka.com.au/gabrielsadaka/gabrielsadaka/mail

    whereas it should only be at www.gabrielsadaka.com.au/gabrielsadaka/mail

    Has anyone had an issue with url rewriting and ASP.NET AJAX and if so how did you fix it?

    I have spent hours trying to fix it and i still can't figure out, the Winhost support said i could maybe setup another url rewrite rule to redirect axd files to the correct place but i cant figure out how to do it.

    Any help would be appreciated

    Kind Regards,

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

    Ray

  3. Thank you for your responses.

    I have gotten really close to fixing the problem, but now i have run into an issue that makes no sense what so ever. There are two files required: webresource.axd and scriptresource.axd however only webresource.axd can be found, for some reason it can't find scriptresource.axd even though they are both being referenced into the same directory.

    I think for some reason that it isn't dynamically generating the scriptresource.axd file.

    I ran the website in firebug and this is what i find out.

    If someone else could do the same and see what i am talking about and then refer to the generated source code.

    This problem is really annoying me now because i have spent ages trying to fix it.

    Has anyone else tried to use ASP.NET AJAX while using a url rewrite script and if so how did they get it working?

    Thank you.
     
  4. You don't do a URL Rewrite on the base directory. I outlined this in the post above, and i'm 100% sure this is the problem you're having (I ran into it before.)

    For example, you have rewritten something like:
    http://qbtournaments.com/tournament.aspx?id=40
    to
    http://qbtournaments.com/40

    THIS WILL CAUSE THE PROBLEM YOU'RE HAVING. You MUST have a separator after the domain:
    http://qbtournaments.com/tournament/40

    is perfectly valid, and won't break all of your AJAX.

    Check, double check, and triple check that you aren't doing this anywhere.
     
  5. Thank you but I'm not using the URL Rewrite module for a dynamic website i'm just using it to redirect the domain pointers to their folders.

    So that each domain i have hosted has it's own folder and in the address bar it doesn't show the subfolder in the url.
     
  6. Ray

    Ray

    As a test I suggest for now you drop any URL redirect or URL rewrite coding from your application. Lets see if that works. If it does that we can definitely narrow it down the redirec or rewrite codes and we can go from there.
     
  7. Thank you ray, yes i tried it without the url rewrite and it worked perfectly.

    It's odd it seems like the webresource.axd file is getting generated fine but for some reason scriptresource.axd isn't getting generated.

    But at least now we know it has something to do with the url rewrite module.

    Maybe if we somehow ignored axd files from the rewrite and let them get generated how they normally would.
     
  8. Thank you for all your help but i gave up on asp.net ajax and went for silverlight which works like a charm and is so much easier to configure.
     
  9. AJAX fails to load when site placed in subfolder

    I believe this will be a problem for anyone who comes from webhost4life, is using asp.net and ajax, and hosts multiple sites in subfolders. Webhost4life handled the ajax url rewriting for us, but for Winhost we need to handle the ajax url rewriting.

    I successfully placed a site within a subfolder using the following rewriting rule, in a web.config file at the root level.

    <rule name="Rewrite to folder1" stopProcessing="true">
    <match url="(.*)" />
    <conditions>
    <add input="{HTTP_HOST}" pattern="^www.mydomain.org$" />
    </conditions>
    <action type="Rewrite" url="mysubfolder/{R:1}" />
    </rule>

    The generated code in default.aspx produces
    <script src="/mysubfolder/ScriptResource.axd?d=JqgWhplkVbNDB-O-ThhHizUoDTYJEM-feibV4yvf46HwrI2N5TzSy72-olJ4bTMQzD63KWlitLqI2oLdioZV-Q2&amp;t=ffffffff966badba" type="text/javascript"></script>


    But the generated code needs to produce
    <script src="/ScriptResource.axd?d=JqgWhplkVbNDB-O-ThhHizUoDTYJEM-feibV4yvf46HwrI2N5TzSy72-olJ4bTMQzD63KWlitLqI2oLdioZV-Q2&amp;t=ffffffff966badba" type="text/javascript"></script>

    I need the code to generate the AJAX references without the subfolder name.
     
    Last edited by a moderator: Oct 14, 2015
  10. Yes i understand what needs to be done, but there is no way to do it, well there is but then you run into another error then another and it keeps going.

    Simple answer is ajax postbacks don't work well with URL rewrite the only thing that does is if you use MVC
     
  11. Ray

    Ray

    So you are using ASP.Net Routing. What is the error message when you use this?
     
  12. i don't actually use it, i just looked it up and everyone said it worked, i ended up making my contact form in silverlight
     
  13. I think gabriel93 summed it up pretty well by saying "Yes i understand what needs to be done, but there is no way to do it, well there is but then you run into another error then another and it keeps going. " I've read a number of posts on the subject but haven't found anyone who's solved the problem.

    Regarding the comment from Ray (Winhost Staff) asking about the error message, please see the very first post to this thread which shows the error message.
     
    Last edited by a moderator: Oct 14, 2015
  14. Ray

    Ray

    Unfortunately the error messages you provided in the first thread is really meaningless and uninformative. Not your fault though.

    Try this. Go to this site and download this application and install it on your computer. Someone told me about it and they claim that it does a really good job capturing errors between calls to the server and the browser. When you get a more descriptive error post it on this thread and we'll look at it.

    http://www.fiddler2.com/fiddler2/
     
  15. I attached the trace as requested but I'm not sure how that helps. The problem is that ajax is generating references to the axd files with the subfolder name. The page errors when loading (ajax failed to load) because it can't find the axd files. Having ajax to not have the subfolder name should fix the problem but I don't have the knowledge to do that.

    For example. This code
    /gasmileagecars/ScriptResource.axd?d=URt4ioym-6d5aZpz8L14j2t0tUvAOzf7HyBPzkq0XMTiyvbZj_nxSrtXfEtaOYylfUAVkR4FJD7jhbcZEk2rzXHRToX2DJhpGcudNpFwTiM1&t=4710cd2

    Needs to be changed to
    /ScriptResource.axd?d=URt4ioym-6d5aZpz8L14j2t0tUvAOzf7HyBPzkq0XMTiyvbZj_nxSrtXfEtaOYylfUAVkR4FJD7jhbcZEk2rzXHRToX2DJhpGcudNpFwTiM1&t=4710cd2


    Thanks.


    # Result Protocol Host URL Body Caching Content-Type Process Comments Custom
    35 200 HTTP www.gasmileagecars.org / 25,580 private text/html; charset=utf-8 iexplore:5148
    36 200 HTTP www.gasmileagecars.org /Content.css 2,541 text/css iexplore:5148
    37 200 HTTP www.gasmileagecars.org /gasmileagecars/WebResource.axd?d=GNZbwmpmN7ioj3lGK9mWps-n02uHzPcdKSl3rWHdCiMuEVuw0bDB3r4ysOdZmZHCEgtkR9CRUbH8EsfZNtthH34Cc0Ji3xYG76PdnBST2_w1&t=634096288756890176 5,396 public Expires: Sat, 21 May 2011 02:54:15 GMT text/css iexplore:5148
    38 200 HTTP www.gasmileagecars.org /StyleSheet.css 2,694 text/css iexplore:5148
    39 200 HTTP www.gasmileagecars.org /gasmileagecars/WebResource.axd?d=ZujnmjPFGuij8kQHntKjEw2&t=633750378833416323 20,794 public Expires: Sat, 21 May 2011 02:54:16 GMT application/x-javascript iexplore:5148
    40 404 HTTP www.gasmileagecars.org /gasmileagecars/ScriptResource.axd?d=gwkq7ruqc9v05sVT1D2QvF1ctMLLCEuR01ynpNt1a14PrH6sj3gOUK-7sSjaBMNukod7hrZSGnOFg2UmnN73Ow2&t=ffffffff966badba 2,576 private text/html; charset=utf-8 iexplore:5148
    41 404 HTTP www.gasmileagecars.org /gasmileagecars/ScriptResource.axd?d=OEVgG9QCJ5U54SoPyj3Qeo4uWEk-dUfLs_0y29r1gmCM6qllVhbj2Ez5RfBKFFT2xSgGaWk9DyNDxQJc1pbiiRUksS4DPVD2NgGWAp0kbYs1&t=2ab97a20 2,576 private text/html; charset=utf-8 iexplore:5148
    42 404 HTTP www.gasmileagecars.org /gasmileagecars/ScriptResource.axd?d=OEVgG9QCJ5U54SoPyj3Qeo4uWEk-dUfLs_0y29r1gmCM6qllVhbj2Ez5RfBKFFT2smT9ww0xFNhvxLQVwx5Lr5s5xKlYhO8eSU-P3DA2E4GfqBrWNzjKS8GX7s7t9nkV0&t=2ab97a20 2,576 private text/html; charset=utf-8 iexplore:5148
    43 404 HTTP www.gasmileagecars.org /gasmileagecars/ScriptResource.axd?d=URt4ioym-6d5aZpz8L14j2t0tUvAOzf7HyBPzkq0XMQMXgTyIpVX7DibnHRrSFUHQIf-35dGoJ0k9bPsR3gskQ2&t=4710cd2 2,576 private text/html; charset=utf-8 iexplore:5148
    44 404 HTTP www.gasmileagecars.org /gasmileagecars/ScriptResource.axd?d=URt4ioym-6d5aZpz8L14j2t0tUvAOzf7HyBPzkq0XMQKqiaFLhSK8KIr0UjA3nNj_7F2bwx4NWFGH2FYYFeUw-HvI7yWQ6g8oPlYOUjOuag1&t=4710cd2 2,576 private text/html; charset=utf-8 iexplore:5148
    45 404 HTTP www.gasmileagecars.org /gasmileagecars/ScriptResource.axd?d=URt4ioym-6d5aZpz8L14j2t0tUvAOzf7HyBPzkq0XMQfIYLzYtFl2-8xX5d2XYo2PexhIDrtikKXvAIQQZ630CcWxzVp-UF_ZXrvSWkVHVw1&t=4710cd2 2,576 private text/html; charset=utf-8 iexplore:5148
    46 404 HTTP www.gasmileagecars.org /gasmileagecars/ScriptResource.axd?d=URt4ioym-6d5aZpz8L14j2t0tUvAOzf7HyBPzkq0XMRXKSLTVhaLYmdg-8I9kY0bZsbdEdXfKg3Xl_Q8itt8Ep0C3yYeKEAJKe7MrsC0tsU1&t=4710cd2 2,576 private text/html; charset=utf-8 iexplore:5148
    47 404 HTTP www.gasmileagecars.org /gasmileagecars/ScriptResource.axd?d=URt4ioym-6d5aZpz8L14j2t0tUvAOzf7HyBPzkq0XMQfIYLzYtFl2-8xX5d2XYo2HGpZLVkYz98-MFidfE1qIoNaEdj4dbxyuTw35wO1ji41&t=4710cd2 2,576 private text/html; charset=utf-8 iexplore:5148
    48 404 HTTP www.gasmileagecars.org /gasmileagecars/ScriptResource.axd?d=URt4ioym-6d5aZpz8L14j2t0tUvAOzf7HyBPzkq0XMTiyvbZj_nxSrtXfEtaOYylfUAVkR4FJD7jhbcZEk2rzXHRToX2DJhpGcudNpFwTiM1&t=4710cd2 2,576 private text/html; charset=utf-8 iexplore:5148
    49 404 HTTP www.gasmileagecars.org /gasmileagecars/ScriptResource.axd?d=URt4ioym-6d5aZpz8L14j2t0tUvAOzf7HyBPzkq0XMSuhaJXl2ffGN9kohq0H_fc3D1xjag6dVyTRtNb6KAyHYSxu0pVNoGCvl6FHBlMonbURUk7bYwUpTyKl01Vym4S0&t=4710cd2 2,576 private text/html; charset=utf-8 iexplore:5148
    50 404 HTTP www.gasmileagecars.org /gasmileagecars/ScriptResource.axd?d=URt4ioym-6d5aZpz8L14j2t0tUvAOzf7HyBPzkq0XMQbAuYR7ubdb2fasWNgSJXj6WB_181w7CvtG9Wz-ovTdCsGfANuzdeOUryZ2Lm0LWgn3Gr6z2sRocZEV1JQFboy0&t=4710cd2 2,576 private text/html; charset=utf-8 iexplore:5148
    51 200 HTTP pagead2.googlesyndication.com /pagead/show_ads.js 12,511 public, max-age=86400 Expires: Sat, 22 May 2010 02:43:03 GMT text/javascript; charset=UTF-8 iexplore:5148
    52 200 HTTP www.gasmileagecars.org /images/dotX_blue.jpg 10,481 image/jpeg iexplore:5148
    53 200 HTTP www.gasmileagecars.org /images/dotY_blue.jpg 10,483 image/jpeg iexplore:5148
    54 200 HTTP www.gasmileagecars.org /images/bl_blue.gif 942 image/gif iexplore:5148
    55 200 HTTP www.gasmileagecars.org /images/br_blue.gif 932 image/gif iexplore:5148
    56 200 HTTP www.gasmileagecars.org /images/tl_blue.gif 939 image/gif iexplore:5148
    57 200 HTTP www.gasmileagecars.org /images/tr_blue.gif 933 image/gif iexplore:5148
    58 200 HTTP pagead2.googlesyndication.com /pagead/expansion_embed.js 14,882 public, max-age=86400 Expires: Sat, 22 May 2010 02:52:08 GMT text/javascript; charset=UTF-8 iexplore:5148
    59 200 HTTP googleads.g.doubleclick.net /pagead/test_domain.js 72 public, max-age=1209600 Expires: Fri, 04 Jun 2010 02:43:38 GMT text/javascript; charset=UTF-8 iexplore:5148
    60 200 HTTP pagead2.googlesyndication.com /pagead/render_ads.js 185 public, max-age=1209600 Expires: Fri, 04 Jun 2010 02:52:30 GMT text/javascript; charset=UTF-8 iexplore:5148
    61 200 HTTP googleads.g.doubleclick.net /pagead/ads?client=ca-pub-8201926421734439&output=html&h=60&slotname=5884154364&w=468&lmt=1274410562&flash=10.0.42.34&url=http%3A%2F%2Fwww.gasmileagecars.org%2F&dt=1274410562325&shv=r20100505&correlator=1274410562571&frm=0&ga_vid=32492393.1267240526&ga_sid=1274410563&ga_hid=936537561&ga_fc=1&u_tz=-240&u_his=3&u_java=1&u_h=1200&u_w=1920&u_ah=1170&u_aw=1920&u_cd=32&u_nplug=0&u_nmime=0&biw=1026&bih=909&eid=33895100&fu=0&ifi=1&dtd=1085&xpc=jItEPMmWg2&p=http%3A//www.gasmileagecars.org 1,591 private, x-gzip-ok="" text/html; charset=UTF-8 iexplore:5148
    62 200 HTTP www.gasmileagecars.org /Images/Banner3.JPG 1,063 image/jpeg iexplore:5148
    63 200 HTTP googleads.g.doubleclick.net /pagead/imgad?id=CM_TuZKynLD5ExDUAxgxMgj2cIU4HRLFxw 12,154 public, max-age=604800 Expires: Fri, 28 May 2010 02:56:16 GMT image/jpeg iexplore:5148
    64 200 HTTP www.gasmileagecars.org /Images/sky7.JPG 36,176 image/jpeg iexplore:5148
    65 200 HTTP googleads.g.doubleclick.net /pagead/ads?client=ca-pub-8201926421734439&output=html&h=125&slotname=2886482123&w=125&lmt=1274410564&flash=10.0.42.34&url=http%3A%2F%2Fwww.gasmileagecars.org%2F&dt=1274410564729&shv=r20100505&prev_slotnames=5884154364&correlator=1274410562571&frm=0&ga_vid=32492393.1267240526&ga_sid=1274410563&ga_hid=936537561&ga_fc=1&u_tz=-240&u_his=3&u_java=1&u_h=1200&u_w=1920&u_ah=1170&u_aw=1920&u_cd=32&u_nplug=0&u_nmime=0&biw=1026&bih=909&eid=33895100&fu=0&ifi=2&dtd=106&xpc=gcIXSTCWuL&p=http%3A//www.gasmileagecars.org 4,046 private, x-gzip-ok="" text/html; charset=UTF-8 iexplore:5148
    66 200 HTTP googleads.g.doubleclick.net /pagead/ads?client=ca-pub-8201926421734439&output=html&h=200&slotname=8798628434&w=200&lmt=1274410564&flash=10.0.42.34&url=http%3A%2F%2Fwww.gasmileagecars.org%2F&dt=1274410564907&shv=r20100505&prev_slotnames=5884154364%2C2886482123&correlator=1274410562571&frm=0&ga_vid=32492393.1267240526&ga_sid=1274410563&ga_hid=936537561&ga_fc=1&u_tz=-240&u_his=3&u_java=1&u_h=1200&u_w=1920&u_ah=1170&u_aw=1920&u_cd=32&u_nplug=0&u_nmime=0&biw=1026&bih=909&eid=33895100&fu=0&ifi=3&dtd=121&xpc=cUbCnThLTC&p=http%3A//www.gasmileagecars.org 4,382 private, x-gzip-ok="" text/html; charset=UTF-8 iexplore:5148
    67 200 HTTP www.gasmileagecars.org /images/arrowr.gif 949 image/gif iexplore:5148
     
  16. Ray

    Ray

  17. Problem fixed.

    Adding the additional condition to each rule fixed the problem. I still have some other "rule" problems with my sites, but now at least the home page loads with AJAX.

    <add input="{URL}" negate="true" pattern="\.axd$" />
     
  18. Ray

    Ray

    What exactly are the problems with your rule?
     
  19. Problem Solved

    Finally found a solution. I now have several asp.net web sites using AJAX in one hosting account. Winhost rocks.

    1. Upload your web site to a new subfolder. In this example I'm using "mysubfolder."
    2. Define the folder as an Application Starting Point (see KB articles). In this example I'm using "mydomainname.com."
    3. Create a Domain Pointer (see KB articles)
    4. Create a web.config file in your root directly.
    5. Add the following information to your web.config file.

    <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
    <system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
    <rewrite>
    <rules>
    <rule name="mydomainname.com" stopProcessing="true">
    <match url=".*" />
    <conditions>
    <add input="{HTTP_HOST}" pattern="^(www.)?mydomainname.com" />
    <add input="{PATH_INFO}" pattern="^/mysubfolder/" negate="true" />
    </conditions>
    <action type="Rewrite" url="\mysubfolder\{R:0}" />
    </rule>
    </rules>
    </rewrite>
    </system.webServer>
    </configuration>
     
    Last edited by a moderator: Oct 14, 2015
  20. Last edited by a moderator: Oct 14, 2015

Share This Page