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
Release: 2023-08-28 14:01:10
forward
1117 people have browsed it

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();
   });
}
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template