D
D
Denis Bredun2020-08-07 02:51:34
ASP.NET
Denis Bredun, 2020-08-07 02:51:34

How do I explicitly specify which of the two Configure method should be called in the Startup class?

using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

namespace ASP_NET_Core_Lessons
{
  public class Startup
  {
    public void ConfigureServices(IServiceCollection services)
    {
    }
    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
      if (env.IsDevelopment())
      {
        app.UseDeveloperExceptionPage();
      }
      app.UseRouting();
      app.UseEndpoints(endpoints =>
      {
        endpoints.MapGet("/", async context =>
              {
                await context.Response.WriteAsync("Hello World!");
          });
      });
    }

    IWebHostEnvironment _env;
    public Startup(IWebHostEnvironment env)
    {
      _env = env;
    }
    public void Configure(IApplicationBuilder app)
    {
      app.UseRouting();

      app.UseEndpoints(endpoints =>
      {
        endpoints.MapGet("/", async context =>
        {
          await context.Response.WriteAsync($"Application Name: {_env.ApplicationName}");
        });
      });
    }
  }
}

How do I explicitly specify which of the two Configure method should be called?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question