How to return status code 200 instead of 403 the default URL of my asp net framework application

49 views Asked by At

In a net core application I can use the MapGet to return status code 200 and a message.

example:

public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IHostApplicationLifetime appLifeTime)
    {
        _logger.Info("Configure starting...");

        try
        {
            RegisterApplicationShutdown(appLifeTime);

            if (env.IsDevelopment())
                app.UseDeveloperExceptionPage();

            app.UseRouting();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
                endpoints.MapGet("/", async context =>
                {
                    context.Response.StatusCode = 200;
                    await context.Response.WriteAsync("MyApp is live!");
                });
            });

            app.UseOpenApi();
            app.UseSwaggerUi3(swaggerUi3Settings => 
            {
                swaggerUi3Settings.Path = "/admin/swagger";
            });

            _logger.Info("Configure ended");
        }
        catch (Exception ex)
        {
            _logger.Error(ex, string.Empty);
            throw;
        }
    }

How can I achieve this in a net framework application

0

There are 0 answers