views:

289

answers:

1

I need to be able to distinguish http 302 redirects from my code that use .net remoting.

In order to connect to the appropriate url we try them in order until one works. In most environments the first url correctly fails with a System.Net.WebException with a status of WebExceptionStatus.NameResolutionFailure. For Customers that use OpenDNS, however this comes back as a HTTP 302 response that redirects to their Guide page. Because I am using .net Remoting the redirect is ignored, and the error I recieve is a System.Runtime.Serialization.SerializationException that is only distinguishable by its message "End of Stream encountered before parsing was completed."

Here's the opendns http response: HTTP/1.0 302 Found Location: http://guide.opendns.com/?url=demonstration.totallyinvalidexceptonmynetwork.com%2Fi%2Fdo%2Fnot%2Fexist.html Content-type: text/html Content-Length: 0 Connection: close Date: Thu, 28 May 2009 20:46:26 GMT Server: OpenDNS Guide

A: 

I assume that to post the request you are using the HttpWebRequest object. Then you can recieve the response in the HttpWebResponse object like bellow. Then you can check the response.StatusCode property. If it is 302 then perform your logic.

HttpWebResponse response = (HttpWebResponse)request.GetResponse(); if (response.StatusCode = HttpStatusCode.Found) { //your code here }

I hope this helps.

Update: If you are using System.Net.Webclient then you can use the you can use its ResponseHeaders property. here is how you can use it:http://msdn.microsoft.com/en-us/library/system.net.webclient.responseheaders.aspx

24x7Programmer