asp.net - Security.Authentication.AuthenticationException: The remote certificate is invalid according to the validation procedure -
i have downloaded trial version of product provides api on https. , inside asp.net mvc web application doing following execute api call trial version of product:-
[httppost] [validateantiforgerytoken] public actionresult create(rackjoin rj, formcollection formvalues) { string controllername = routedata.values["controller"].tostring(); if (modelstate.isvalid) { var message = ""; var status = ""; long assetid = new long(); xmldocument doc = new xmldocument(); using (var client = new webclient()) { var query = httputility.parsequerystring(string.empty); foreach (string key in formvalues) { query[key] = this.request.form[key]; } query["username"] = system.web.configuration.webconfigurationmanager.appsettings["apiusername"]; query["password"] = system.web.configuration.webconfigurationmanager.appsettings["apipassword"]; string apiurl = "https://win-spdev:8400/servlets/assetservlet"; //code goes here….. var url = new uribuilder(apiurl); url.query = query.tostring();
but following exception:-
error occurred:system.security.authentication.authenticationexception: remote certificate invalid according validation procedure. @ system.net.security.sslstate.startsendauthresetsignal(protocoltoken message, asyncprotocolrequest asyncrequest, exception exception) @ system.net.security.sslstate.checkcompletionbeforenextreceive(protocoltoken message, asyncprotocolrequest asyncrequest) @ system.net.security.sslstate.startsendblob(byte[] incoming, int32 count, asyncprotocolrequest asyncrequest) @ system.net.security.sslstate.processreceivedblob(byte[] buffer, int32 count, asyncprotocolrequest asyncrequest) @ system.net.security.sslstate.startreadframe(byte[] buffer, int32 readbytes, asyncprotocolrequest asyncrequest) @ system.net.security.sslstate.startreceiveblob(byte[] buffer, asyncprotocolrequest asyncrequest) @ system.net.security.sslstate.checkcompletionbeforenextreceive(protocoltoken message, asyncprotocolrequest asyncrequest) @ system.net.security.sslstate.startsendblob(byte[] incoming, int32 count, asyncprotocolrequest asyncrequest) @ system.net.security.sslstate.processreceivedblob(byte[] buffer, int32 count, asyncprotocolrequest asyncrequest) @ system.net.security.sslstate.startreadframe(byte[] buffer, int32 readbytes, asyncprotocolrequest asyncrequest) @ system.net.security.sslstate.startreceiveblob(byte[] buffer, asyncprotocolrequest asyncrequest) @ system.net.security.sslstate.checkcompletionbeforenextreceive(protocoltoken message, asyncprotocolrequest asyncrequest) @ system.net.security.sslstate.startsendblob(byte[] incoming, int32 count, asyncprotocolrequest asyncrequest) @ system.net.security.sslstate.processreceivedblob(byte[] buffer, int32 count, asyncprotocolrequest asyncrequest) @ system.net.security.sslstate.startreadframe(byte[] buffer, int32 readbytes, asyncprotocolrequest asyncrequest) @ system.net.security.sslstate.startreceiveblob(byte[] buffer, asyncprotocolrequest asyncrequest) @ system.net.security.sslstate.checkcompletionbeforenextreceive(protocoltoken message, asyncprotocolrequest asyncrequest) @ system.net.security.sslstate.startsendblob(byte[] incoming, int32 count, asyncprotocolrequest asyncrequest) @ system.net.security.sslstate.forceauthentication(boolean receivefirst, byte[] buffer, asyncprotocolrequest asyncrequest) @ system.net.security.sslstate.processauthentication(lazyasyncresult lazyresult) @ system.net.tlsstream.callprocessauthentication(object state) @ system.threading.executioncontext.runinternal(executioncontext executioncontext, contextcallback callback, object state, boolean preservesyncctx) @ system.threading.executioncontext.run(executioncontext executioncontext, contextcallback callback, object state, boolean preservesyncctx) @ system.threading.executioncontext.run(executioncontext executioncontext, contextcallback callback, object state) @ system.net.tlsstream.processauthentication(lazyasyncresult result) @ system.net.tlsstream.write(byte[] buffer, int32 offset, int32 size) @ system.net.pooledstream.write(byte[] buffer, int32 offset, int32 size) @ system.net.connectstream.writeheaders(boolean async)
baring in mind can call api without problems, if directly call api web browser follow :-
https://win-spdev:8400/servlets/assetservlet?username=tmsservice&password=test2test2&assettype=rack&operation=updateasset&assetname=rack9090909858585&accountname=group&sitename=test%20site&productname=rackproductone
so problem related api on https , , since working trial version of product inside development machine should install valid certificate? or problem not related security certification ? thanks
the problem haven't configured valid ssl certificate. since valid ssl certificate cost money, development purposes, guess used auto-signed certificate. ignore error settings servercertificatevalidationcallback
static property in application_start
:
system.net.servicepointmanager.servercertificatevalidationcallback += (s, cert, chain, sslpolicyerrors) => true;
note: avoid doing in production. when deploy on live make sure using valid ssl certificate.
Comments
Post a Comment