简体   繁体   English

async、await、context 和 next 在当前上下文中不存在

[英]async, await, context and next does not exist in the current context

I just created a new empty web application using Core 2.2 and wanted to add a piece of middleware but I am not allowed to do so.我刚刚使用 Core 2.2 创建了一个新的空 Web 应用程序,并想添加一个中间件,但我不允许这样做。

app.Use(async (context, next)) =>
        {
            await next;
        }

but it doesn't recognize either async, context, next or await.但它不能识别异步、上下文、下一步或等待。 I've tried to search online but haven't come across anything with this trivial problem.我试过在线搜索,但没有遇到任何关于这个微不足道的问题。 Anyone knows what's causing it?有谁知道是什么原因造成的? I am using community 2019我正在使用社区 2019

It should be它应该是

app.Use(async (context, next) =>
    {
        await next();
    })

app.Use() accepts a function as parameter but you pass only async (context, next) as parameter. app.Use()接受一个函数作为参数,但你只传递async (context, next)作为参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM