0

I'm building a proxy, and I want it to return a 403 forbidden in case the host in the request is found in a "black host list".

I couldn't realize how I can create a "HttpWebResponse" without sending the request and change the Status Code to 403.

Should I create a request with the given Url

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

and do some manipulation on this request, or can I do it other way? Also, which manipulation can I do to get a 403 response?

Thanks :)

ballade4op52
  • 2,142
  • 5
  • 27
  • 42
Aviram Fireberger
  • 3,910
  • 5
  • 50
  • 69
  • You just need to return to the client a 403 status. How you do this will depend upon how you receive HTTP requests from the proxy user? – Alex K. Apr 11 '14 at 14:33
  • Just ask if the server is in a black hole list and if, you just throw an exception or return anything and say "403". – Dominic B. Apr 11 '14 at 14:35
  • I'm receiving it from an object "HttpListenerContext" (saving as context). I'm taking out the Url url = context.Request.RawUrl Compare to the black list *** until here I implemented all but the proxy server need to return a "HttpWebResponse" which in "Non black listed URI" I got from: HttpWebResponse response = this.GetResponse(request); – Aviram Fireberger Apr 11 '14 at 14:43
  • Have a look here. http://stackoverflow.com/questions/5649852/asp-net-web-service-i-would-like-to-return-error-403-forbidden – CathalMF Apr 11 '14 at 14:43

1 Answers1

0

Well I added:

context.Response.StatusCode = 403; context.Response.Close(); 

In chrome I get an empty page, and don't know why),

and in Internet Explorer I get the default 403 error.

ballade4op52
  • 2,142
  • 5
  • 27
  • 42
Aviram Fireberger
  • 3,910
  • 5
  • 50
  • 69