12 September 2022

ASP.NET Core disable authentication in development environment

    You can bypass authorization in development environment by applying AllowAnonymousAttribute() to your endpoints. as below code 


 public void Configure(IApplicationBuilder app, IWebHostEnvironment env)

        {

           //-----------------------

            app.UseRouting();

            app.UseEndpoints(endpoints =>

            {

                if (env.IsDevelopment())

                    endpoints.MapControllers().WithMetadata(

                        new AllowAnonymousAttribute());

                else

                    endpoints.MapControllers();

            });

        //---------------------------

          }

No comments:

Post a Comment