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

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?}");
});
}
}



主站蜘蛛池模板: 皮山县| 大名县| 六安市| 望都县| 香港| 岚皋县| 广南县| 蒲城县| 象州县| 清水河县| 股票| 宜黄县| 耒阳市| 盈江县| 莲花县| 阿鲁科尔沁旗| 舟曲县| 高淳县| 罗甸县| 普兰店市| 阿鲁科尔沁旗| 泗阳县| 离岛区| 平乐县| 东阿县| 巴彦县| 高陵县| 万年县| 加查县| 绥芬河市| 保山市| 香港| 东丰县| 晋宁县| 巴彦县| 芒康县| 北辰区| 湘潭市| 乡宁县| 澄城县| 襄樊市|