Search code examples
c#.netsslhttps

Odd Variation of the "The request was aborted: Could not create SSL/TLS secure channel" error - .NET Web Forms


I've got an odd variation of the "The request was aborted: Could not create SSL/TLS secure channel". Using .NET Web Forms, I have a HttpWebRequest the yields the error, but only after the initial compile. If I simply refresh the webpage, it works fine and does what it needs to. I'd like to find a solution to get rid of the initial error altogether.

I've tried a number of different solutions to prevent the initial error from happening, but have not found any success.

I'm curious if anyone else has seen the error happen in this way? If so, have you found a solution?


Solution

  • As mentioned in the title, I had a odd situation where I'd get this error "The request was aborted: Could not create SSL/TLS secure channel", but only after being recompiled or after the AppPool would recycle. After the first/initial error, all subsequent requests would work fine, until the next recompile or AppPool recyle.

    Going back to the framework suggestions, I reviewed the targetFramework which was 4.7. I reviewed the web.config and noticed that I did not have targetFramework set inside the httpRuntime tag (in fact, I didn't even have the httpRuntime tag. Adding the following solved the issue - no more errors on the initial load:

    <system.web>
        <httpRuntime targetFramework="4.7" />
        ...
    

    Note: I did have targetFramework set within my tag, but adding the <httpRuntime/> tag with targetFramework="4.7" resolved the problem.

    This change did cause another issue with UnobtrusiveValidation mode, but that was easily solved by following this suggestion: WebForms UnobtrusiveValidationMode requires a ScriptResourceMapping for jquery