ASP.NET Core redirect http to https

前端 未结 6 1567
陌清茗
陌清茗 2021-01-01 17:11

I have created a redirect rules in my web.config to redirect my website from http to https. The issue i have is that every single link on the website is now https. I have a

6条回答
  •  囚心锁ツ
    2021-01-01 17:18

    You will need to add also the following code in .net core 2.1

    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }
        else
        {
            app.UseExceptionHandler("/Error");
            app.UseHsts();
        }
    
        app.UseHttpsRedirection();
        app.UseStaticFiles();
        app.UseCookiePolicy();
    
        app.UseMvc();
    }
    

    and the following part in service configuration

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

提交回复
热议问题