# Pure.NETCoreExtentensions

https://github.com/purestackorg/Pure.NETCoreExtensions

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;
<h2>Hello World!</h2>
@DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss fff") <h3>Config</h3>
<p>
ConnectionString: @ConfigurationManager.Configuration.GetConnectionString()
</p>
<h3>AppSetting</h3>
<p>
<table>
<tr>
<td>Key1</td>
<td> @ConfigurationManager.AppSettings["Key1"]</td>
</tr>
<tr>
<td>Key2</td>
<td> @ConfigurationManager.AppSettings["Key2"]</td>
</tr>
<tr>
<td>Key2</td>
<td> @ConfigurationManager.AppSettings["Key3"]</td>
</tr>
</table> </p> <h3>Env</h3>
<p>
<table>
<tr>
<td>ApplicationName</td>
<td> @GlobalHostEnvironment.ApplicationName </td>
</tr>
<tr>
<td>ContentRootPath</td>
<td> @GlobalHostEnvironment.ContentRootPath </td>
</tr>
<tr>
<td>EnvironmentName</td>
<td> @GlobalHostEnvironment.EnvironmentName </td>
</tr>
<tr>
<td>WebRootPath</td>
<td> @GlobalHostEnvironment.WebRootPath </td>
</tr> </table> </p> <h3>Platform</h3>
<p>
<table>
<tr>
<td>OS</td>
<td> @Platform.OS </td>
</tr>
<tr>
<td>Is64BitOperatingSystem</td>
<td> @Platform.Is64BitOperatingSystem </td>
</tr>
<tr>
<td>OSDescription</td>
<td> @Platform.OSDescription </td>
</tr>
<tr>
<td>OSArchitecture</td>
<td> @Platform.OSArchitecture </td>
</tr>
<tr>
<td>ProcessArchitecture</td>
<td> @Platform.ProcessArchitecture </td>
</tr>
<tr>
<td>RuntimeType</td>
<td> @Platform.RuntimeType </td>
</tr> </table> </p> <h3>HttpContext</h3>
<p>
<table>
<tr>
<td>Current</td>
<td> @GlobalHttpContext.Current </td>
</tr>
<tr>
<td>Request.GetClientIpAddress </td>
<td> @GlobalHttpContext.Current.Request.GetClientIpAddress() </td>
</tr>
<tr>
<td>Request.IsLocalRequest </td>
<td> @GlobalHttpContext.Current.Request.IsLocalRequest() </td>
</tr>
<tr>
<td>Request.GetConnectionId </td>
<td> @GlobalHttpContext.Current.Request.GetConnectionId() </td>
</tr>
<tr>
<td>Request.ContentLength </td>
<td> @GlobalHttpContext.Current.Request.GetRequestId() </td>
</tr>
<tr>
<td>Request.GetUserAgent </td>
<td> @GlobalHttpContext.Current.Request.GetUserAgent() </td>
</tr> <tr>
<td>Response.ContentLength </td>
<td> @GlobalHttpContext.Current.Response.ContentLength </td>
</tr>
<tr>
<td>Response.ContentType </td>
<td> @GlobalHttpContext.Current.Response.ContentType </td>
</tr> <tr>
<td>Response.StatusCode </td>
<td> @GlobalHttpContext.Current.Response.StatusCode </td>
</tr>
</table> </p>

截图

NET Core 拓展方法和中间件集合(支持NET Core2.0+)的更多相关文章

  1. 开源且功能强大的C# 扩展方法类库Pure.Ext,包含1000+个拓展方法 (支持.Net Framework和.Net Core)

    先上地址 Github: https://github.com/purestackorg/pure.ext Gitee: https://gitee.com/purestack/pure.ext 扩展 ...

  2. .NET Core中间件的注册和管道的构建(2)---- 用UseMiddleware扩展方法注册中间件类

    .NET Core中间件的注册和管道的构建(2)---- 用UseMiddleware扩展方法注册中间件类 0x00 为什么要引入扩展方法 有的中间件功能比较简单,有的则比较复杂,并且依赖其它组件.除 ...

  3. 反射 DataTable拓展方法 转实体对象、实体集合、JSON

    Mapper类 using System; using System.Collections.Generic; using System.Data; using System.Globalizatio ...

  4. asp.net core中写入自定义中间件

    首先要明确什么是中间件?微软官方解释:https://docs.microsoft.com/zh-cn/aspnet/core/fundamentals/middleware/?tabs=aspnet ...

  5. asp.net core mvc 管道之中间件

    asp.net core mvc 管道之中间件 http请求处理管道通过注册中间件来实现各种功能,松耦合并且很灵活 此文简单介绍asp.net core mvc中间件的注册以及运行过程 通过理解中间件 ...

  6. ASP.NET CORE 管道模型及中间件使用解读

    说到ASP.NET CORE 管道模型不得不先来看看之前的ASP.NET 的管道模型,两者差异很大,.NET CORE 3.1 后完全重新设计了框架的底层,.net core 3.1 的管道模型更加灵 ...

  7. asp.net core 3.1 自定义中间件实现jwt token认证

    asp.net core 3.1 自定义中间件实现jwt token认证 话不多讲,也不知道咋讲!直接上代码 认证信息承载对象[user] /// <summary> /// 认证用户信息 ...

  8. 用UseMiddleware扩展方法注册中间件类

    用UseMiddleware扩展方法注册中间件类 .NET Core中间件的注册和管道的构建(2)---- 用UseMiddleware扩展方法注册中间件类 0x00 为什么要引入扩展方法 有的中间件 ...

  9. Zepto 添加手势判断拓展方法(思路+原理)

    一.前言 这几个月事情比较多,写了一些博客都没有来得及整理发布,今天刚好有一位同事在开发前端页面的时候用到了手势判断.所以翻出了之前写的 demo,顺便整理一下作为记录. 手势判断在各种应用中都十分常 ...

随机推荐

  1. urllib2模块的基本使用(四)

    urllib2库的基本使用 所谓网页抓取,就是把URL地址中指定的网络资源从网络流中读取出来,保存到本地. 在Python中有很多库可以用来抓取网页,我们先学习urllib2. urllib2 是 P ...

  2. javascript的中的new

    考察 ECMAScript 语言规范中 new 运算符的定义: The new Operator The production NewExpression : new NewExpression is ...

  3. 206. Reverse Linked List + 92. Reverse Linked List II

    ▶ 关于单链表翻转的两个问题. ▶ 206. 翻转整个单链表. ● 自己的代码,9 ms,使用了递归. class Solution { public: ListNode* reverseList(L ...

  4. lombok 的使用

    参考:https://blog.csdn.net/motui/article/details/79012846

  5. oracle 截取字符(substr),检索字符位置(instr)

    常用函数:substr和instr 1.SUBSTR(string,start_position,[length])    求子字符串,返回字符串 解释:string 元字符串 start_posit ...

  6. HTTP 返回码 400

    400(错误请求)服务器不理解请求的语法 404表示页面不存在 返回500表示内部服务出错, 返回301表示资源永久性跳转 HTTP 500 – 内部服务器错误 HTTP 500.100 – 内部服务 ...

  7. Apache HBase 集群安装文档

    简介: Apache HBase 是一个分布式的.面向列的开源 NoSQL 数据库.具有高性能.高可靠性.可伸缩.面向列.分布式存储的特性. HBase 的数据文件最终落地在 HDFS 之上,所以在 ...

  8. eclipse中debug改变变量的值

    step1:debug断点到变量的下一行,在debug试图的右上角variables中看到该变量的值: step2:鼠标右键点击str出现下图,选择Change Value... step3:点击Ch ...

  9. sqlserver job 执行时间

    select instance_id,jh.run_date,jh.job_id,jh.step_name, case jh.run_status then 'failed' then 'Succee ...

  10. write()和print()还有<%= %>的细微区别

    1.首先介绍write()和print()方法的区别: (1).write():仅支持输出字符类型数据,字符.字符数组.字符串等 (2).print():可以将各种类型(包括Object)的数据通过默 ...