小编moh*_*adi的帖子

如何激活中间件

我必须在其他地方激活它还是你可以帮助我?当我运行该项目时,它直接进入控制器并且中间件不运行。

这是我的中间件。

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)
        {
        
        }
    }    
}
Run Code Online (Sandbox Code Playgroud)

c# asp.net-core asp.net-core-middleware asp.net-core-webapi

1
推荐指数
1
解决办法
825
查看次数