博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
NET Core 拓展方法和中间件集合(支持NET Core2.0+)
阅读量:5152 次
发布时间:2019-06-13

本文共 5649 字,大约阅读时间需要 18 分钟。

# Pure.NETCoreExtentensions

NET Core 拓展方法和中间件集合(支持NET Core2.0+)

包含拓展方法:

DistributedCacheExtensions
ConfigurationExtensions
CookiesExtensions
ServiceCollectionExtensions
EnvironmentExtensions
HttpContextExtensions
HttpRequestExtentions
FormFileExtentions
HeaderDictionaryExtensions
DefaultIdentityUserClaimsExtensions
LoggerFactoryExtensions
UrlHelperExtensions
SmtpEmailSenderExtensions
WebHostBuilderExtensions
ApplicationBuilderExtensions

包含中间件:

FriendlyExceptionsMiddleware
HtmlMinificationMiddleware
HttpExceptionMiddleware
InternalServerErrorOnExceptionMiddleware
NoServerHttpHeaderMiddleware
ClientRateLimitMiddleware
IpRateLimitMiddleware
StatisticsMiddleware

常用基类:
BaseController
BaseControllerWithIdentity
TokenBucketLimitingService
LeakageBucketLimitingService
Platform

 

使用说明:

1.引用相关包:

<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.0.3" />

<PackageReference Include="Microsoft.AspNetCore.Identity" Version="2.0.3" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.0.4" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.0.3" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="2.0.2" />
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="2.0.2" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.0.2" />
<PackageReference Include="Microsoft.Extensions.Identity.Stores" Version="2.0.3" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="2.0.2" />

2.引用命名空间

using Pure.NetCoreExtensions

3.配置 Startup.cs 文件

public void Configure(IApplicationBuilder app, IHostingEnvironment env)        {            if (env.IsDevelopment())            {                app.UseDeveloperExceptionPage();            }                        app.UseMvc(routes =>            {                routes.MapRoute(                    name: "default",                    template: "{controller=HelloWorld}/{action=Index}/{id?}");            });                        //global middleware            app.UseGlobalHostingEnvironment(env)                .UseGlobalHttpContext()                .UseGlobalLoggerFactory()                .UseGlobalErrorHandling()               ;                      app.Run(async (context) =>            {                await context.Response.WriteAsync("Hello World!");            });        }

 

4.完成 !

 

下面测试代码和截图:

@{    ViewData["Title"] = "Index";    Layout = "_Layout";}@using Pure.NetCoreExtensions;

Hello World!

@DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss fff")

Config

ConnectionString: @ConfigurationManager.Configuration.GetConnectionString()

AppSetting

Key1 @ConfigurationManager.AppSettings["Key1"]
Key2 @ConfigurationManager.AppSettings["Key2"]
Key2 @ConfigurationManager.AppSettings["Key3"]

Env

ApplicationName @GlobalHostEnvironment.ApplicationName
ContentRootPath @GlobalHostEnvironment.ContentRootPath
EnvironmentName @GlobalHostEnvironment.EnvironmentName
WebRootPath @GlobalHostEnvironment.WebRootPath

Platform

OS @Platform.OS
Is64BitOperatingSystem @Platform.Is64BitOperatingSystem
OSDescription @Platform.OSDescription
OSArchitecture @Platform.OSArchitecture
ProcessArchitecture @Platform.ProcessArchitecture
RuntimeType @Platform.RuntimeType

HttpContext

Current @GlobalHttpContext.Current
Request.GetClientIpAddress @GlobalHttpContext.Current.Request.GetClientIpAddress()
Request.IsLocalRequest @GlobalHttpContext.Current.Request.IsLocalRequest()
Request.GetConnectionId @GlobalHttpContext.Current.Request.GetConnectionId()
Request.ContentLength @GlobalHttpContext.Current.Request.GetRequestId()
Request.GetUserAgent @GlobalHttpContext.Current.Request.GetUserAgent()
Response.ContentLength @GlobalHttpContext.Current.Response.ContentLength
Response.ContentType @GlobalHttpContext.Current.Response.ContentType
Response.StatusCode @GlobalHttpContext.Current.Response.StatusCode

截图

转载于:https://www.cnblogs.com/purestack/p/9174325.html

你可能感兴趣的文章
C语言基础小结(一)
查看>>
STL中的优先级队列priority_queue
查看>>
UE4 使用UGM制作血条
查看>>
浏览器对属性兼容性支持力度查询网址
查看>>
OO学习总结与体会
查看>>
虚拟机长时间不关造成的问题
查看>>
校门外的树2 contest 树状数组练习 T4
查看>>
面试整理:Python基础
查看>>
Python核心编程——多线程threading和队列
查看>>
Program exited with code **** 相关解释
查看>>
装服务器,测试数据库,简单的maven命令
查看>>
升级Firefox8后watir-webdriver出现错误“unable to obtain stable firefox connection in 60 seconds”...
查看>>
第6章 Overlapped I/O, 在你身后变戏法 ---被激发的 Event 对象 -4
查看>>
植物大战僵尸中文年度版
查看>>
26、linux 几个C函数,nanosleep,lstat,unlink
查看>>
001.RAID简介
查看>>
投标项目的脚本练习2
查看>>
第五次实验
查看>>
201521123107 《Java程序设计》第9周学习总结
查看>>
runtime的基本应用
查看>>