ASP. NET Core uses URL Rewrite middleware for HTTP redirection to HTTPS

Source: Internet
Author: User

In a traditional ASP. NET program, we can redirect HTTP requests to HTTPS by configuring the URL rewrite feature of IIS. However, this method does not work in ASP. NET Core applications. In the ASP. NET Core application, we can implement this function through a middleware called URL rewriting. First, make sure that the project already references the Microsoft.AspNetCore.Rewrite package, and if not, you can add a reference through the NuGet manager. Next, just add the following code to the Configure method of the Startup.cs file:

var options = new Rewriteoptions ()    . Addredirecttohttpspermanent (); app. Userewriter (options);

Notice: The above code comes from the Microsoft.AspNetCore.Rewrite namespace.

ASP. NET Core uses URL Rewrite middleware for HTTP redirection to HTTPS

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.