NET Core 拓展方法和中间件集合(支持NET Core2.0+)
# 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.引用相关包:
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>Configh3> <p> ConnectionString: @ConfigurationManager.Configuration.GetConnectionString() p> <h3>AppSettingh3> <p> <table> <tr> <td>Key1td> <td> @ConfigurationManager.AppSettings["Key1"]td> tr> <tr> <td>Key2td> <td> @ConfigurationManager.AppSettings["Key2"]td> tr> <tr> <td>Key2td> <td> @ConfigurationManager.AppSettings["Key3"]td> tr> table> p> <h3>Envh3> <p> <table> <tr> <td>ApplicationNametd> <td> @GlobalHostEnvironment.ApplicationName td> tr> <tr> <td>ContentRootPathtd> <td> @GlobalHostEnvironment.ContentRootPath td> tr> <tr> <td>EnvironmentNametd> <td> @GlobalHostEnvironment.EnvironmentName td> tr> <tr> <td>WebRootPathtd> <td> @GlobalHostEnvironment.WebRootPath td> tr> table> p> <h3>Platformh3> <p> <table> <tr> <td>OStd> <td> @Platform.OS td> tr> <tr> <td>Is64BitOperatingSystemtd> <td> @Platform.Is64BitOperatingSystem td> tr> <tr> <td>OSDescriptiontd> <td> @Platform.OSDescription td> tr> <tr> <td>OSArchitecturetd> <td> @Platform.OSArchitecture td> tr> <tr> <td>ProcessArchitecturetd> <td> @Platform.ProcessArchitecture td> tr> <tr> <td>RuntimeTypetd> <td> @Platform.RuntimeType td> tr> table> p> <h3>HttpContexth3> <p> <table> <tr> <td>Currenttd> <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>
截图