W5100 HttpListenerResponse RedirectLocation is Null

I’m trying to set the RedirectLocation property of the W5100 HttpListenerResponse class, and am getting exceptions because this property is null.

I checked the docs and it doesn’t say anything about being not supported.

Am I missing something?

I figured it out :slight_smile:

Although this property is a string type, it is initially set to null. If you set it, and then read it, the value you set is returned.

Ok. Now I can set this property, and I also set the StatusCode to “Redirect” and the StatusDescription to “Found”, but it’s still not working. It appears the Location header is not being set. Here are the http headers returned to my browser:

GET / HTTP/1.1
Accept: image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-shockwave-flash, application/x-ms-application, application/x-ms-xbap, application/vnd.ms-xpsdocument, application/xaml+xml, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, /
Accept-Language: en-us
User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET4.0C; .NET4.0E)
Accept-Encoding: gzip, deflate
Host: jdisprinklers
Connection: Keep-Alive

HTTP/1.1 302 Found
Connection: Close

Sorry I keep responding to my own posts, but I have a work-around for this problem.

Instead of setting RedirectLocation, just set these properties:

this.httpResponse.Headers.Add("Location", <full URL of the redirect location>);
this.httpResponse.StatusCode = (int)HttpStatusCode.Redirect;
this.httpResponse.StatusDescription = "Found";