【发布时间】:2018-03-19 16:22:57
【问题描述】:
我以以下方式设置了应用程序管道:
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.Use(async (context,next) => {
await context.Response.WriteAsync("Custom MiddleWare");
await next.Invoke();
});
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseWelcomePage(new WelcomePageOptions
{
Path = "/Welcome"
});
app.Run(async (context) =>
{
await context.Response.WriteAsync(Environment.NewLine+"Greetings");
});
}
当我转到 http://localhost:port/ 页面时,我得到以下输出:
自定义中间件
问候
但是http://localhost:port/welcome 的欢迎页面不起作用并报错:
无法访问此网站
现在,如果我像这样修改管道,它会得到修复:
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseWelcomePage(new WelcomePageOptions
{
Path = "/Welcome"
});
app.Use(async (context, next) => {
await context.Response.WriteAsync("Custom MiddleWare");
await next.Invoke();
});
app.Run(async (context) =>
{
await context.Response.WriteAsync(Environment.NewLine+"Greetings");
});
}
我试图了解在第一种情况下没有调用 UseWelcomePage 中间件的原因?
【问题讨论】:
标签: asp.net-core asp.net-core-middleware