3

Question Background: This question is part of my other question, I posted this new question to make things easy to understand, the main question link is this: LINK , In this link you can find full brief information of my project and a solutions for loading CSS with context.rewritepath issue.

in my project, I wrote context.rewritepath in global.asax to redirect user request to different location without changing addressbar address.

Issue is: without context.rewritepath jquery ajax is working perfectly;calling webmethod with response back in json. but when i am using context.rewritepath then jquery ajax response back is html instead of json.

here are the live links:

jasbir.bhinderblink.com

bhinderblink.com/users/jasbir/default.aspx

both links are calling same page from server. first is with context.rewritepath and second is without context.rewritepath. As demo test, On this page you can click top second or third text box and it will give you a type box to save data to database.

You will notice that first link generates error and if you go to firebug java HelloWorld POST response then you will see it is returning html instead of json, second link returns json data

enter image description here enter image description here

Cœur
  • 37,241
  • 25
  • 195
  • 267
JSB
  • 215
  • 5
  • 16
  • You need to clarify how to use your example pages. When I try the second link you provided, I get a status 500 error page. – B2K Jun 24 '14 at 14:56
  • now it is working, i was testing some mime types and it start showing 500 error. i re-uploaded project. – JSB Jun 24 '14 at 22:37
  • There are some key pieces of information missing in your question, like the code in global.asax that performs the context.rewritepath and the code which is supposed to generate your json response. We've got nothing to go on except the symptoms. In the future, you'll need to provide the code which is causing the problem, as well as it's results. Given that the question is incomplete, all I can offer is some advice to workaround the issue. – B2K Jun 25 '14 at 15:12
  • hello B2k I added background and link to top of this question. this question is part of my other question. to make things easy to understand I started this new question. full code and information for global.asax is in that link. – JSB Jun 25 '14 at 15:31
  • I up voted you for providing the needed detail to answer your question. – B2K Jun 25 '14 at 16:34

2 Answers2

1

You can always try just returning the correct mime type. Also, you could use the full url to HelloWorld in your ajax post url.

   url: "/users/jasbir/default.aspx/HelloWorld",

UPDATE:

Your problem, based upon the linked question is that you are losing the /HelloWorld portion of your request when the rewrite is performed.

If Directory.Exists(Server.MapPath("~/users/" & parameters(i))) Then
    Context.RewritePath("/users/" & parameters(i) & HttpContext.Current.Request.Path, False)                    
    Return
Else
    Context.RewritePath("/error.aspx")
    Return
End If
B2K
  • 2,541
  • 1
  • 22
  • 34
  • I already tried this but no solution. please take a look to link as I provided in my main question for reference. – JSB Jun 25 '14 at 15:33
  • so what is your suggestion, how to capture /HelloWorld portion? i try to put Context.Request.Path in global.asax file as you showed in your code example, it ends with a error on server. – JSB Jun 25 '14 at 22:22
  • just for testing your code type this address http:// www. jasbir.bhinderblink.com. and to test without your suggested code type this address jasbir.bhinderblink.com/ – JSB Jun 25 '14 at 23:20
  • its not working, now it is not able to find default.aspx page. could you please explain me how to capture HttpContext.Current.Request.Path output, so we will comes to know what actually going on? – JSB Jun 27 '14 at 01:49
  • HttpContext.Current.Request.Path is the same as your originalPath variable from the linked question. If that's not working, I'm not sure what to tell you. – B2K Jun 29 '14 at 17:37
  • project is loading css, all images, background image, scripts. css file is in same path/location. i am really not understand why jquery not loading Helloworld webmethod... Today i also try **asmx** but same result. how wordpress ppl solved this issue!!!! – JSB Jul 02 '14 at 00:33
  • 1
    Wordpress uses the web server's rewrite rules. This is handled before the request gets sent to asp.net for processing. We use the rewrite rules built into iis7 and [ISAPI Rewrite](http://www.isapirewrite.com) for older servers. – B2K Jul 03 '14 at 14:57
0

Solution for Jquery ajax call to webmethod with vb.net context.rewritepath...

In main page I added this....

<base href="http://www.bhinderblink.com/users/jasbir/">

and this stackoverflow link helped to fix the issue with this code:-

<httpProtocol>
   <customHeaders>
   <add name="Access-Control-Allow-Origin" value="*" />
   <add name="Access-Control-Allow-Headers" value="Origin, X-Requested-With, Content-Type, Accept" />
   </customHeaders>
</httpProtocol>
Community
  • 1
  • 1
JSB
  • 215
  • 5
  • 16