当前位置:网站首页>. net core add Middleware
. net core add Middleware
2022-04-22 21:15:00 【Xiaodou whole sugar (Cx)】
The middleware class must contain RequestDelegate And one. async Method
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")// Suppose... In the route querystring contain password And is 123, Then let continue the visit
{
if (context.Request.HasJsonContentType())
{
context.Items["test"] = "123";
}
await _requestDelegate(context);// So let's keep going
}
else
{
context.Response.StatusCode = 401;
}
}
}
}
Inject
app.UseMiddleware<MiddleWare>();
https://www.tutorialsteacher.com/core/how-to-add-custom-middleware-aspnet-core
版权声明
本文为[Xiaodou whole sugar (Cx)]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204221816273420.html
边栏推荐
- DSPACE simulates simple accident scene
- WampServer 搭建本地服务器及 XSS 基本原理和初步实践(一)
- 东吴证券X袋鼠云:数据轻松可取、毫秒级反应能力,东吴证券做对了什么?
- [database learning 01]
- nodejs笔记5
- Comprehensive comparison of the most complete software testing tools and packet capturing tools
- Count the number of characters C
- Leetcode-238 - product of arrays other than itself
- [tool configuration] generated by designer in visual studio Solution to the problem of UI file not being updated in time
- Question bank and simulation examination of work permit for safety management personnel of hazardous chemical business units in 2022
猜你喜欢

Analysis of tourism products: travel around

MySQL specifies field sorting and user-defined sorting location

Nodejs notes 2

毕业设计第8周学习记录

Knowledge of machine vision

Summary of software testing knowledge points | JMeter implementation Interface Association

QTP11.5/UFT含中文汉化包

Selenium_Webdriver视频自动化脚本分享

HDLBits(十 一)学习笔记——有限状态机(FSM onehot - Fsm serialdp)

2022-4-22 Leetcode 279. Complete square
随机推荐
Rong Lianyun joined hands with China Academy of information and communications to start the development of a series of standards for office instant messaging software
Knowledge of machine vision
Comprehensive comparison of the most complete software testing tools and packet capturing tools
Win10 installation neo4j
beyond compare 强制使用二进制传输,保证文件一样
FreeModbus快速入门指南
.bashrc . bash_ profile . bash_ logout . bash_ history
BLE---Advertisement data format & service
QT使用windeployqt.exe打包程序
Select distinct statement de duplication
Lizard book learning Day1 - overview of machine learning
JMeter complete set of data
Hdlbits (XI) learning notes - finite state machine (FSM onehot - FSM serialdp)
Big talk test data (II): acquisition of concept test data
[NOIP2012]借教室
LeetCode-209-长度最小的子数组
WampServer 搭建本地服务器及 XSS 基本原理和初步实践(一)
nodejs笔记2
Nodejs notes 5
Qtp11 tutorial