How to redirect from http to https in ASP.NET Core?

Hello, I would like to know, how can force user to redirect from http(not secured) page to https(secured page) in core?

I am using core boilerplate template.

Asked by:- jaya
: 1596 At:- 3/27/2018 12:48:17 PM
ASP.NET core

2 Answers
profileImage Answered by:- Sam

In core, you can set up a redirect from HTTP to HTTPS on the web-server or use middleware Rewrite in your startup.cs 

  var options = new RewriteOptions()
                .AddRedirectToHttps(StatusCodes.Status301MovedPermanently, 44384);

Complete code would look like this

 public void Configure(
            IApplicationBuilder app, 
            IHostingEnvironment env)
            var options = new RewriteOptions()
                .AddRedirectToHttps(StatusCodes.Status301MovedPermanently, 44384);

In startup.cs you can configure Https redirect by using code below

public void ConfigureServices(
            IServiceCollection services)
            //add the MVC filter for https 
            services.AddMvc(options =>
                options.Filters.Add(new RequireHttpsAttribute());
At:- 3/28/2018 10:06:19 AM
thanks got it 0
By : jaya - at :- 4/3/2018 12:51:06 PM

profileImage Answered by:- vikas_jk

For those you want's to migrate http to https in MVC ,please refer this link's answer

It has both the way's explained using web.config and IIS for ASP.NET and MVC

At:- 3/30/2018 11:27:03 AM Updated at:- 3/30/2018 11:27:41 AM
I wanted to migrate http to https in .NET Core, @Sam's answer worked for me, thanks 0
By : jaya - at :- 4/3/2018 12:51:44 PM

Login/Register to answer
Register directly by posting answer/details

Full Name *

Email *

By posting your answer you agree on privacy policy & terms of use

Subscribe Now

Subscribe to our weekly Newsletter & Keep getting latest article/questions in your inbox weekly