/// <summary> /// /// </summary> /// <param name="context"></param> /// <returns></returns> public async Task Invoke(HttpContext context) { try { if (context.Request.Method.Equals(HttpMethod.Post.Method) && context.Request.Path.HasValue) { if (Options.LoginPath.Equals(context.Request.Path)) { await Handler.Login(context).ConfigureAwait(false); return; } else if (Options.LogoutPath.Equals(context.Request.Path)) { await Handler.Logout(context).ConfigureAwait(false); return; } else if (Options.AccessDeniedPath.Equals(context.Request.Path)) { await Handler.AccessDenied(context).ConfigureAwait(false); return; } } await Next.Invoke(context).ConfigureAwait(false); } catch (Exception ex) { throw new SampleAuthenticationException("中间件运行时发生异常.", ex); } }