Learn

Another common built-in middleware component is the UseHttpsRedirection() method. Let’s dive deeper to find out how this method helps our web applications.

HyperText Transfer Protocol, more commonly called HTTP, is a group of standards defining communication between web servers and browsers. HTTP’s job is helping the web server (where our web application will live) and the browser (what the user will be using to interact with our application) communicate with each other.

HyperText Transfer Protocol Secure, more commonly known as HTTPS, is an extension of HTTP for securely transmitting communications between the web server and browser. Part of our job as a developer is making sure our web application is both functional and as secure as possible. HTTPS is the industry standard communication protocol, as HTTP is widely regarded as “unsecure”, and should be avoided for any public facing websites. However, what happens when a user sends a request to our application using HTTP?

Well, we have a few options. We could close the connection, present the user with an error page, or we could simply re-route their request through the more secure HTTPS pathway. Typically, the latter option is more common and thankfully we have a built-in middleware component which can easily handle this task.

The UseHttpsRedirection() method is the middleware component used to capture HTTP requests and redirect them to the more secure HTTPS. Since the redirection is done in our configuration the user never even has to know the redirection occurred. Like the other middleware components we’ve reviewed, the UseHttpsRedirection() method should also be called from the Configure() method of the Startup class.

Instructions

1.

Add the UseHttpsRedirection() component to the middleware pipeline. It should appear immediately before the UseStaticFiles() component.

Sign up to start coding

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?