当前位置:网站首页>.net core 添加中间件
.net core 添加中间件
2022-04-22 18:16:00 【小兜全糖(Cx)】
中间件类必须含有RequestDelegate 以及一个async 方法
namespace WebApplication1
{
public class MiddleWare
{
private readonly RequestDelegate _requestDelegate;
public MiddleWare(RequestDelegate requestDelegate)
{
_requestDelegate = requestDelegate;
}
public async Task InvokeAsync(HttpContext context)
{
string pwd = context.Request.Query["password"];
if (pwd == "123")//假如路由中的querystring含有password且是123,则让继续访问
{
if (context.Request.HasJsonContentType())
{
context.Items["test"] = "123";
}
await _requestDelegate(context);//继续往下执行
}
else
{
context.Response.StatusCode = 401;
}
}
}
}
注入
app.UseMiddleware<MiddleWare>();
https://www.tutorialsteacher.com/core/how-to-add-custom-middleware-aspnet-core
版权声明
本文为[小兜全糖(Cx)]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_43632687/article/details/122691399
边栏推荐
- Fastjson 2 is coming, the performance continues to improve, and it can fight for another ten years
- 接口测试 Mock 实战(二) | 结合 jq 完成批量化的手工 Mock
- 电脑硬件都有哪些?
- 秒云助力中电科32所发布“基于拟态应用集成框架的SaaS云管理平台解决方案”
- I still don't understand the relative path and absolute path. This article takes you to analyze it briefly
- leetcode-470. 用 Rand7() 实现 Rand10()
- 国产芯片DP9637-K总线收发器替代L9637D芯片和SI9241
- SAP ui5 data type learning notes
- 『程序员延寿指南』:跟着码农干,多活20年!
- 图像的卷积——【torch学习笔记】
猜你喜欢
![[fundamentals of interface testing] Chapter 10 | explain the pre script of postman request and its working principle in detail](/img/b1/64d4996fb27939dfbd98a6f0da8671.png)
[fundamentals of interface testing] Chapter 10 | explain the pre script of postman request and its working principle in detail

Secyun assisted the "SaaS cloud management platform solution based on pseudo application integration framework" released by CETC 32
Esprima ECMAScript 解析架构
![[fundamentals of interface testing] Part 8 common assertions of postman and the working principle of assertions](/img/7c/eaf5802b7ff801cf1f6b06da986537.png)
[fundamentals of interface testing] Part 8 common assertions of postman and the working principle of assertions

Build China's cloud ecology | Huayun data and Baixin complete product compatibility and mutual certification and jointly promote the high-quality development of information innovation industry

Packet capture analysis of interface protocol TCP protocol

Design the test paper storage scheme of ten million students management system

es6 Generator函数的使用

18730 涂色问题 (快速幂的两种写法)

秒雲助力中電科32所發布“基於擬態應用集成框架的SaaS雲管理平臺解决方案”
随机推荐
Dpdk captures traffic from a given port / queue
SAP ui5 data type learning notes
Youqilin 22.04 lts version is officially released | ukui 3.1 opens a new experience!
MySQL----索引
uniapp处理强制刷新问题
B-tree [concept]
Huawei router realizes the connection between headquarters and branches through MPLS virtual private network
In depth analysis of filter execution principle (BitSet mechanism and caching mechanism)
rm格式的文件怎么打开?
【C语言进阶篇】一篇文章带你认清结构、枚举和联合
[fundamentals of interface testing] Chapter 11 | detailed explanation of postman associated interface and batch execution use case set
Future direction of digital shooting range
Second Cloud a aidé la solution SaaS Cloud Management Platform basée sur un cadre d'intégration d'applications simulé publié par le CETC 32
National information exchange model (NIEM) operation manual
golang-gin-websocket问题
MySQL排序与分页
【浏览器】谷歌浏览器自带翻译失效
电脑上怎么快速切换显示不同的软件界面
数字化靶场的未来方向
Deleted items can be recovered even after the outlook Deleted Items folder is empty