XmlHttpResponse problems with Response.Redirect("...")

david7777

Freshman
Joined
Feb 17, 2005
Messages
33
I have the following problem:

I am currently implementing AJAX (Asynchronous Javascript And Xml) into certain areas of my website. Anyway - it uses the JavaScript XmlHttpResponse object to send and receive data to and from the server without having to post back the page.

Everything is working great, until I try to use a Response.Redirect() on the server side.

Here is my example:

I have a content page which is access restricted to registered users, and this is how it SHOULD work:

1. The page (RestrictedPage.aspx) loads an empty template.
2. Once loaded, I use the JavaScript XmlHttpResponse object to fetch content to fill the template (without reloading the page). I request data from, lets say, content.aspx
3. content.aspx first checks to see that the user is logged in
- 3.1) Not logged in - it redirects to an appropriate page to output the "access denied" XML
- 3.2) Logged in - Redirects to appropriate page to output XML content
4. Now the info is returned to the XmlHttpResponse object on the client side (RestrictedPage.aspx).
5. I use JavaScript to work with the XML, and do appropriate things depending on what the returned XML is... (like tell the user to log in, or use DOM objects to fill the template with content)

All of this works great WITHOUT redirects involved. My problem is that as soon as I use Response.Redirect() in step 3.1 or 3.2 above, instead of just the XmlHttpResponse URL redirecting, the actual client is redirected, and the browser loads what should be loading in the XmlHttpResponse object...

I have a feeling there is no work around, but if anyone knows why this happens, please let me know!??

Thanks!
 
Well I would think that your custom handler for this main page would just have other methods that output the desired XML - not redirect to another page. The application is just doing what you're telling it to do - redirect to a aspx page...

The idea of JavaScript RPC is to have one stateful page...
 
mark007, the transfer statement does the same thing... I already tried that.

bri189a - I agree, but things are made very difficult when using multi output with .net. What I mean is that I am using the same page to output either normal HTML using web controls etc, or output XML, depending on the querystring. The problem here is that the viewstate and other default hidden fields that .net includes in the page can not be taken out of the page. If you have a <form runat="server"> tag in the page, the hidden tags will always be there, and this will of course mess up any XML structure I ouptut. For that reason, I tried to redirect to another page to output the XML.

I guess I will just need to create two seperate pages for the different output or something...
 
Back
Top