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

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



主站蜘蛛池模板: 太和县| 察哈| 米泉市| 鄂托克前旗| 呈贡县| 托克逊县| 蚌埠市| 郸城县| 保山市| 岗巴县| 盐池县| 徐闻县| 通许县| 黄冈市| 商水县| 新余市| 滨海县| 清苑县| 临西县| 河源市| 齐齐哈尔市| 定襄县| 留坝县| 元谋县| 宜宾县| 阿拉善左旗| 金山区| 阳西县| 华阴市| 博兴县| 贵德县| 珲春市| 金堂县| 北辰区| 当阳市| 云龙县| 新竹市| 木兰县| 广昌县| 广东省| 府谷县|