官术网_书友最值得收藏!

Startup.cs

The Startup class is needed by ASP.NET Core applications to manage the application's request pipeline, configure services, and for dependency injection.

Different Startup classes can be created for different environments; for example, you can create two Startup classes in your application, one for the development environment and the other for production. You can also specify that a Startup class be used for all environments.

The Startup class has two methods—Configure(), which is compulsory and is used to determine how the application should respond to HTTP requests, and ConfigureServices(), which is optional and is used to configure services before the Configure method is called. Both methods are called when the application starts:

 public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}

public IConfiguration Configuration { get; }

// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
}

app.UseStaticFiles();

app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
}



主站蜘蛛池模板: 抚顺县| 万载县| 安远县| 沙洋县| 凭祥市| 洛阳市| 萝北县| 双江| 同江市| 屏东市| 宜宾县| 利津县| 台南市| 龙岩市| 泾川县| 桓台县| 来宾市| 江华| 怀宁县| 永川市| 淳安县| 商水县| 阿合奇县| 司法| 恩施市| 沁阳市| 从江县| 云南省| 山西省| 霍邱县| 界首市| 潼关县| 工布江达县| 南阳市| 永兴县| 永定县| 连南| 合川市| 类乌齐县| 沾益县| 漳平市|