Home >Backend Development >C#.Net Tutorial >What is the use of the Configure() method of the startup class in C# Asp.net Core?

What is the use of the Configure() method of the startup class in C# Asp.net Core?

PHPz
PHPzforward
2023-08-28 14:01:101106browse

C# Asp.net Core中启动类的Configure()方法有什么用?

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.

Example

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!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete