Click here to Skip to main content
15,303,572 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How to check 'http forbidden 403' websites from URL using c# code ?
Please provide example , am beginner in c#
Thanks !!
Sergey Alexandrovich Kryukov 24-Jul-13 10:55am
Example of what, client side or server side? If client, there is nothing to do: forbidden is forbidden, you cannot make is accessible.
Or do you want to test the site?
jeffingeorge 24-Jul-13 10:59am
I just want to get the exception message when trying to access the URL

1 solution

Hello Jeff,

Following code snippet should help you get started.
WebRequest request = WebRequest.Create (strURL);
HttpWebResponse response = (HttpWebResponse)request.GetResponse ();
if (response.StatusCode == HttpStatusCode.Forbidden) {
    // Code to handle the Forbidden Error

More ifnormation can be found in MSDN documentation[^] for respective classes.

Thomas Daniels 24-Jul-13 11:18am
Prasad Khandekar 24-Jul-13 11:19am
Thank's a lot.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900