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;    
        }
    }
}

About the author

Paul Seal

A .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

How to upgrade Umbraco safely

I have upgraded quite a few Umbraco sites recently and I thought I would share my experience and str…

Read Post

Umbraco - The Friendliest Community

This post gives you an idea of what the Umbraco community is like and why I think it is the best tec…

Read Post

How to upload multiple files at once in an MVC form

This post will help you if you need to upload multiple files at once in an MVC form.  The examples…

Read Post

How to fix the MVC Textbox date time format issue

This post shows you how you can remove the time off the end of a date value when rendering it in an…

Read Post