0

I want to redirect a HTTP request to HTTPS. How can I do in .Net Core 2.0?

I tried to add the below code in the startup.cs file but this is not working. Can any one help me for this?

services.AddHttpsRedirection(options =>
{
    options.RedirectStatusCode = StatusCodes.Status307TemporaryRedirect;
    options.HttpsPort = 443;
});

Details about the code:

When I run my project first time, the Configure() and AddHttpsRedirection() gets called.

Then after I change https to http only after that it's not working means its not call any function from stratup.cs

I did this code and try to redirect to https, but page is just loading, it's not redirecting, Even worse, I am not able to call AddHttpsRedirection function.

2
  • Does this answer your question? ASP.NET Core redirect http to https Commented Jan 3, 2020 at 7:46
  • Check if you forget to add app.UseHttpsRedirection(); in your Configure-Method (Startup-Class) Commented Jan 3, 2020 at 8:19

1 Answer 1

0

I have a .NET Core 2.1 project and I use the following:

Startup.cs

public void Configure(IApplicationBuilder app, IHostingEnvironment env, IServiceProvider services)
{
    ...
    app.UseHttpsRedirection();
    ...
}
Sign up to request clarification or add additional context in comments.

1 Comment

i had also use this but i m not able do solve this issue

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.