Pages

Showing posts with label Error. Show all posts
Showing posts with label Error. Show all posts

Tuesday, October 16, 2018

HttpClient, Web API REST service and self signed Certificates

I recently came up with the problem where my web API was hosted locally on IIS using self signed certificate. 

The same code was working absolutely fine in Production, but for local, it was throwing exception because locally I had installed a self signed IIS Express certificate.

Here is the exception that I received (in full)...

System.AggregateException
  HResult=0x80131500
  Message=One or more errors occurred.
  Source=mscorlib
  StackTrace:
   at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
   at ..............
   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass13.b__c(Object instance, Object[] methodParameters)
   at System.Threading.Tasks.TaskHelpers.RunSynchronously[TResult](Func`1 func, CancellationToken cancellationToken)
Inner Exception 1:
HttpRequestException: An error occurred while sending the request.
Inner Exception 2:
WebException: The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.
Inner Exception 3:
AuthenticationException: The remote certificate is invalid according to the validation procedure.

The only help that I got from the exception was from Inner Exception 3: AuthenticationException: The remote certificate is invalid according to the validation procedure.

So, to look into the details, I realized that the Self Signed Certificate from my local IIS is causing the problem. After a bit more googling I came up with this solution.


 #if DEBUG  
         //Accept all server certificate  
         ServicePointManager.ServerCertificateValidationCallback =  
           delegate (object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)  
           {  
             return true;  
           };  
 #endif  

Notice the #if DEBUG to make sure that the self signed certificate only works in case of local development environment only.

This sorted out the issue as now, I was bypassing the Certificate check using my own delegate.

Thursday, December 23, 2010

Deployment Windows 2003 IIS Problem 404 Error

This is a normal problem with Deployments, whenever people deploy their ASP.Net application on windows 2003 server. They face this problem. A 404 (Page Not Found) Error is shown.

This error normally arise when the sequence of installation is wrong.

Following steps must be taken to prevent the error to arise:

  1. make sure that the asp.net is registered with the IIS. You can register the asp.net with the IIS using aspnet_regiis.exe using '-i' switch. The aspnet_regiis.exe is located at <%WIN%>\Microsoft.Net\Framework\ folder
  2. It is often seen that registering the asp.net with IIS has no effect on the error mentioned above. In that case, you must make sure that the corresponding version in the Web Service Extensions in the IIS Manager is marked as 'Allowed'.
You can achieve this by doing the following steps:
  • Point to Start -> Run
  • Type inetmgr and then press enter. This will open the IIS Console on the server
  • Expand the server node and then click the 'Web Service Extensions' folder
  • Make sure that the corresponding ASP.Net version in the right pane is marked as 'Allowed'.
  • If not, select the corresponding version of asp.net in the right pane and click 'Allow' button.
Now try browsing the website again. It should run as a charm.