I have an application that sometimes needs to execute some server requests to make sure that these requests are properly blocked. In other words, the expected server response is 403 Forbidden.
With a piece of code like this:
HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create(protectedPage);
httpRequest.Method = WebRequestMethods.Http.Head;
WebResponse response = HttpRequest.GetResponse();
a is WebExceptionthrown into the last line.
When profiling code, this exception in the try / catch block has a performance impact that I want to avoid.
Is there a way to check the server response, expecting 403, not being able to catch the exception (but avoiding using sockets directly)?
source
share