Click here to Skip to main content
15,943,245 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi ,

I am accessing web page by using httpwebrequest and httpwebresonse class's, but i am facing one issue.
Issue : When i am accessing the web page, the response, i am getting for Login Page which has SSL certificate(https://Loginpage.) not for requsted page, it is not bypassing login page.

My code is below..

string strurl = "http://Requstedpage";
        Uri uri = new Uri(strurl);
        ServicePointManager.ServerCertificateValidationCallback +=
object sender1,
X509Certificate certificate,
X509Chain chain,
SslPolicyErrors sslPolicyErrors)
    return true;

HttpWebRequest request = HttpWebRequest.Create(uri) as HttpWebRequest;
request.ContentType = "application/x-www-form-urlencoded";
request.AllowAutoRedirect = true;
request.PreAuthenticate = true;
request.Credentials = CredentialCache.DefaultCredentials;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
string responseText = string.Empty;
using (StreamReader reader = new StreamReader(response.GetResponseStream()))
    responseText = reader.ReadToEnd();
string RespCookie = response.Cookies.ToString();
Updated 21-Mar-11 0:10am

1 solution

All that you need to do is:

public void ConfigureSSL()
    ServicePointManager.ServerCertificateValidationCallback = CertChecker;

private bool CertChecker(object sender, X509Certificate certificate,
    X509Chain chain, SslPolicyErrors errors)
    return certificate.Subject == "Certificate SSL Subject for your site";//

Call ConfigureSSL() method before the first request.
Share this answer

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