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

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



主站蜘蛛池模板: 界首市| 玉环县| 桑植县| 天全县| 珠海市| 永修县| 池州市| 昌吉市| 登封市| 南陵县| 申扎县| 湘乡市| 安西县| 临沭县| 喀喇| 信丰县| 峨眉山市| 陈巴尔虎旗| 从江县| 阜平县| 吴江市| 济源市| 沿河| 东安县| 拜泉县| 富顺县| 来宾市| 剑川县| 秦皇岛市| 忻城县| 尚志市| 隆林| 象州县| 柘荣县| 陆川县| 炎陵县| 阳朔县| 滦南县| 阿克陶县| 德格县| 山丹县|