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

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



主站蜘蛛池模板: 嘉峪关市| 黎川县| 平遥县| 隆德县| 界首市| 通江县| 三都| 连州市| 和顺县| 邵东县| 偏关县| 江山市| 景东| 桦南县| 德江县| 将乐县| 碌曲县| 西和县| 略阳县| 庆安县| 大兴区| 陵水| 襄城县| 河津市| 灵寿县| 扶绥县| 宣恩县| 宣城市| 乳山市| 横峰县| 滨州市| 建德市| 武乡县| 卢氏县| 北碚区| 阿巴嘎旗| 天祝| 崇明县| 雷山县| 宿州市| 略阳县|