首页 > 其他分享 >.Net Core 中间件

.Net Core 中间件

时间:2023-01-06 14:58:29浏览次数:42  
标签:Core app 中间件 next CorsMiddleware Net public

自定义中间件的使用

在项目启动配置文件中Configure方法

public void Configure(IApplicationBuilder app, IWebHostEnvironment env){

 app.UseMiddleware<CorsMiddleware>();

}

 

CorsMiddleware 函数

public class CorsMiddleware
{

  //请求委托

  private readonly RequestDelegate next;

  //注入服务

  public CorsMiddleware(RequestDelegate next)
  {
    this.next = next;
  }
  

  //请求实例

  public async Task Invoke(HttpContext context)
  {

    //相关的操作

  }

  //调用下一个

  await next(context);
}

标签:Core,app,中间件,next,CorsMiddleware,Net,public
From: https://www.cnblogs.com/pipitnt/p/17030460.html

相关文章