1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
| using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
namespace MockSchool
{
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
// 设置 EnableEndpointRouting 为 false 是为了使用 MVC 默认路由
//services.AddMvc(a => a.EnableEndpointRouting = false);
// 使用 AddControllersWithViews 而不使用 AddMvc 是为了不引入 RazorPages
// 等未用到的服务
services.AddControllersWithViews(a => a.EnableEndpointRouting = false);
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
// 先处理静态文件
app.UseStaticFiles();
app.UseMvcWithDefaultRoute();
app.Run(async (context) =>
{
await context.Response.WriteAsync("Hello World!");
});
}
}
}
|