1

I have a response.redirect(url) which goes to another site.
In the event this fails, how should I redirect again to a redirect fail page?

  1. The request is being sent from the code behind an aspx page.
  2. I have an httpmodule in place. Can it be used?
TheCodeArtist
  • 21,479
  • 4
  • 69
  • 130
confuzzled
  • 43
  • 1
  • 4
  • 1
    The initial redirect goes to a completely different site, or just another page on your application? – Joe Enos Mar 25 '11 at 20:55

2 Answers2

6

response.redirect(url) tells browser to request the "url" so you can not control if this url call is failed in browser.

What you can do is do a HTTP GET HEAD to that url first to see if you get http 200 response and then do a response.redirect(url).

Numenor
  • 1,686
  • 12
  • 20
  • agreed. If the new page is on a different server outside of the OP's control then the only way to do this is first test if that server is available then decide whether to redirect or not – NotMe Mar 25 '11 at 20:56
  • 1
    Nitpick: rather than performing an HTTP GET, consider performing an HTTP HEAD instead and save yourself some bandwidth - http://stackoverflow.com/questions/830435/how-to-check-if-a-file-exists-on-a-server-using-c-and-the-webclient-class – 48klocs Mar 25 '11 at 21:03
  • @Chris - So, regardless of the client and server (normally) having completely different networks and see the web differently, a check on the server side would mean something on the client side? – Oded Mar 25 '11 at 21:03
  • @Oded: As you're attempting to point out, it is entirely possible that the server does indeed see things differently. This could be the case if the server is locked down from making external requests or if the network it is on is configured in such a way that certain sites are blocked. Both of which are possible and even likely. If this is the case then this answer would utterly fail. However, if it is sufficiently important to be able to perform this action then I'd hope the OP (and perhaps his/her boss) could cajole the net admins into allowing those outbound requests. – NotMe Mar 25 '11 at 21:06
  • @Nitpick yes http head makes more sense for bandwidth usage. – Numenor Mar 26 '11 at 11:06
1

This doesn't make much sense - if a redirect fails, how will the server ever find out?

A redirect tells the browser to go to a different page - if this fails, it fails on the browser and the server has no way to know about it.

Oded
  • 489,969
  • 99
  • 883
  • 1,009
  • Not true completely. You can catch it and redirect in the catch. I think the problem is how to tell it to redirect without "Response" because the object is null. – Anthony Graglia May 17 '11 at 12:04