Showing posts with label environment. Show all posts
Showing posts with label environment. Show all posts

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();

            });

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

          }