The configure method exists in the startup class of an ASP.NET Core application
The Configure method is where you can configure the application request pipeline Use the built-in provided IApplicationBuilder instance for your application IoC container
Configure method has these three parameters IApplicationBuilder by default, IWebHostEnvironment and ILoggerFactory .
At runtime, the ConfigureServices method is called before the Configure method. This registers a custom service with the IoC container and can be used Configuration method.
IWebHostEnvironment: Provides information about web hosting environments and The application is running.
IApplicationBuilder: Define a class to provide configuration mechanism The application's request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env){ if (env.IsDevelopment()){ app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Error"); app.UseHsts(); } app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseRouting(); app.UseAuthorization(); app.UseEndpoints(endpoints =>{ endpoints.MapRazorPages(); }); }
The above is the detailed content of What is the use of the Configure() method of the startup class in C# Asp.net Core?. For more information, please follow other related articles on the PHP Chinese website!