asp.net core-默认中间件功能

UseRouting和UseEndPoints

UseRouting和UseEndPoints必定是成对出现的。

当请求来的时候,调用了UseRouting之后,就能获取到配置的路由

对于web api来说,用的如下形式

             app.UseRouting();


            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });    

使用静态文件

asp.net core 通过app.UseStaticFiles来实现静态文件的获取

比如添加了该中间件,那么就可以直接通过路径请求本地的css,js或者图片。

还有种配置如下

在 appsetting.json里面添加
{
    // 服务器文件配置
    "AvatarFileOption": {
    "ServerFileStorePath": "C:\files\avatar",
    "RequestPath": "/avatar"
  }
}

然后在startup中添加如下中间件
app.UseStaticFiles(Configuration, "AvatarFileOption"); // 头像文件
原文地址:https://www.cnblogs.com/xiaojidanbai/p/14230754.html