我使用的是asp.net核心,並且我希望在調用完整的Web應用程序之前從請求中獲取多個數據。在一箇中間件中定義一個變量,可用於下列變量
所以我創建了一箇中間件來做到這一點。我發現了一個方法來檢查我想要的一切,但我不知道如何將一個變量傳遞給下面的中間件
app.Use(async (context, next) => {
var requestInfo = GetRequestInfo(context.Request);
if(requestInfo == null)
{
context.Response.StatusCode = 404;
return;
}
// How do I make the request info available to the following middlewares ?
await next();
});
app.Run(async (context) =>
{
// var requestInfo = ???
await context.Response.WriteAsync("Hello World! - " + env.EnvironmentName);
});
是否有從中間件到別人傳遞數據的好辦法? (這裏我用app.Run
,但我想有這一切,MVC)
哦,這是更簡單,是的! – glacasa