With TLS 1.0 and 1.1 being depricated, you will no doubt need to force your .NET websites / services to run over TLS 1.2 

This blog post shows you how you can do that.

MVC and Web API

In the root of the site, find the global.asax file, right click on it and view code.

In this file, there should be an Application_Start method.

In this method, add this line to force TLS 1.2

namespace YourApplication
{
    public class WebApiApplication : System.Web.HttpApplication
    {
        protected void Application_Start()
        {
            //**Add this line**
            System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
            //**Add this line**

            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
        }
    }
}

Umbraco

If you are using Umbraco, you can put it in the ApplicationStarted method in a class which inherits from IApplicationEventHandler like this:

namespace YourApplication.EventHandlers
{
    public class RegisterEvents : ApplicationEventHandler
    {
        protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
        {
            System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;    
        }
    }
}

Thank you

If you would like to say thank you or support me, then please become a Patron on my Patreon Page. You will get stickers if you join on the $5 rate.

Sponsor this website

If you would like to sponsor this website you can do that here

About the author

Paul Seal

Umbraco MVP and .NET Web Developer from Derby (UK) who specialises in building Content Management System (CMS) websites using MVC with Umbraco as a framework. Paul is passionate about web development and programming as a whole. Apart from when he's with his wife and son, if he's not writing code, he's thinking about it or listening to a podcast about it.

Related Posts

5 things a developer should do before asking for help

In this post I give you my opinions and experience about when I think you should ask for help and wi…

Read Post

Some questions answered about Umbraco Cloud

In this post I give you some answers to the questions I had about Umbraco Cloud at the beginning of…

Read Post

How to solve the Web API error 405 Method Not Allowed

This post shows you how to solve this 405 error and get it working properly.

Read Post

10 Web Developer tips I learned at Codegarden 2018

In this post I share with you 10 web developer tips and tricks I learned at Codegarden 2018

Read Post