Purpose Of Configure Method in Asp.Net core
In Http request pipeline, Configure method defines the middleware. Middlewares are the software components that are combined into an applicaiton pipeline to manage request and response.
For Example:
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
app.UseApplicationInsightsRequestTelemetry();
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseBrowserLink();
} else {
app.UseExceptionHandler("/Home/Error");
}
app.UseApplicationInsightsExceptionTelemetry();
app.UseStaticFiles();
app.UseMvc(routes => {
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
In the above given code,UseExceptionHandler is a middleware. UseExceptionHandler is inserted as a middleware to the pipeline which will catch exceptions, log them, reset the request path, and re-execute the request.
Also Read:
Purpose Of Configureservices in Asp.net Core?
How to use Exception filters in ASP.NET Core MVC?