c# - Disable SSL client certificate on *some* WebAPI controllers? -


edit future readers: unfortunately, bounty awarded answer doesn't work; nothing can now. read own answer below (through testing) - confirmed work minimal code changes

we have azure cloud service (webrole) that's entirely in asp.net webapi 2.2 (no mvc, front end angular). of our controllers/rest endpoints talk 3rd party cloud service on ssl (client cert auth/mutual auth) , rest of controllers/endpoints talk html5/angularjs front end, on ssl (but more traditional server auth ssl). don't have non-ssl endpoint. we've enabled client ssl via cloud service startup task like:

if not defined appcmd set appcmd=%systemroot%\system32\inetsrv\appcmd.exe %appcmd% unlock config /section:system.webserver/security/access 

issue: setting site-wide when users hit first page (say https://domain.com, returns index.html angularjs) browser asks them client ssl cert. (image below)

if there way either

  1. limit client ssl certificate requests webapi controllers talk 3rd party cloud service?

or

  1. skip client ssl auth our front end powering webapi controllers?

our server's web.config complex relevant snippet below:

<system.webserver>   <security>     <access sslflags="sslnegotiatecert" />   </security> </system.webserver> 

and screenshot of client hitting regular webapi endpoint yet attempting client ssl authentication (happens in browser, chrome, firefox or ie) enter image description here

you allow plain http traffic on web.config level , write custom delegating handler in web api pipeline this. can find client cert delegating handler here , here. make handler active "per-route" found in example here:

this route configuration like.

public static class webapiconfig {     public static void register(httpconfiguration config)     {         config.routes.maphttproute(             name: "route1",             routetemplate: "api/{controller}/{id}",             defaults: new { id = routeparameter.optional }         );          config.routes.maphttproute(             name: "route2",             routetemplate: "api2/{controller}/{id}",             defaults: new { id = routeparameter.optional },             constraints: null,             handler: new customcertificatemessagehandler()  // per-route message handler         );          config.messagehandlers.add(new someothermessagehandler());  // global message handler     } } 

please note in case need "per-route" delegating handlers must not put them in global message handler list.


Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -