我必須在其他地方激活它還是你能幫我?當我運行專案時,它直接進入控制器并且中間件不運行。
這是我的中間件。
public class AuthenticationMiddleWare
{
private RequestDelegate nextDelegate;
public AuthenticationMiddleWare(RequestDelegate next, IConfiguration config)
{
nextDelegate = next;
}
public async Task Invoke(HttpContext httpContext)
{
try
{
// somecode
await nextDelegate.Invoke(httpContext);
}
catch (Exception ex)
{
}
}
}
uj5u.com熱心網友回復:
確保您已Configure在 Startup 類的方法中注冊了中間件。
public class Startup
{
...
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseMiddleware<AuthenticationMiddleWare>();
}
}
參考
Configure 方法 - ASP.NET Core 中的應用程式啟動
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/410245.html
標籤:
上一篇:對于需要來自Azuresqldb的資料的端點,Azureapi在本地作業,但不能在Azure部署中作業。帶有硬編碼資料的端點很好
