c# - attach a client certificate through code when connecting to an OData service -


am trying query odata web.api hosted on iis7. site requires client cert. how attach certificate query? using web.api 2, framework 4.5, mvc5

string certpath = @"e:\clientcertificate.cer";  uri uri = new uri("https://server/odata/");  var container = new courseservice.container(uri); container.clientcertificate = new x509certificate(certpath); 

the extension container class achieved reading this: http://bartwullems.blogspot.co.uk/2013/03/odata-attach-client-certificate-through.htm

you attach certificate request in sendrequest2 event yourself:

    context.sendingrequest2 += (sender, eventargs) =>         {             // can safely cast requestmessage httpwebrequestmessage if not in batch.             if (!eventargs.isbatchpart)             {                 ((httpwebrequestmessage)eventargs.requestmessage).httpwebrequest.clientcertificates.add(thecertificate);             }         }; 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -