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

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



主站蜘蛛池模板: 察哈| 潼南县| 石林| 房产| 津市市| 庐江县| 吉水县| 德令哈市| 炎陵县| 澳门| 桐庐县| 沧源| 红安县| 佛教| 阿拉善盟| 甘肃省| 天祝| 行唐县| 榆树市| 竹溪县| 台州市| 内江市| 巫山县| 枣阳市| 洪湖市| 农安县| 玉田县| 准格尔旗| 新昌县| 油尖旺区| 门源| 大竹县| 北碚区| 察雅县| 石屏县| 五莲县| 玉龙| 陆河县| 景德镇市| 凌海市| 巴南区|