Search code examples
aspnetboilerplateasp-net-core-spa-services

Asp.net Core 2.2 app.UseHttpsRedirection() is not defined


When I try to use the app.UseHttpsRedirection() method it gives me a build error saying:

'IApplicationBuilder' does not contain a definition for 'UseHttpsRedirection' and no accessible extension method 'UseHttpsRedirection' accepting a first argument of type 'IApplicationBuilder' could be found (are you missing a using directive or an assembly reference?

I have tried installing the Microsoft.AspNetCore.HttpsPolicy nuget package.

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            app.UseAbp(); // Initializes ABP framework.

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Error");
            }

            app.UseStaticFiles();
            app.UseHttpsRedirection(); 
            app.UseAuthentication();

            app.UseCookiePolicy();
            app.UseHttpMethodOverride

            app.UseJwtTokenMiddleware();

            app.UseSignalR(routes =>
            {
                routes.MapHub<AbpCommonHub>("/signalr");
            });

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "defaultWithArea",
                    template: "{area}/{controller=Home}/{action=Index}/{id?}");

                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
        }


Solution

  • UseHttpsRedirection is an Extension method hidden in the Microsoft.AspNetCore.HttpsPolicy DLL. You have to add it (through NuGet or manually)

    See the accepted answer here for more DLLs you may need