Global.asax.cs中相关方法
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | protected void Session_Start( object sender, EventArgs e) { #if DEBUG //debug 登陆默认设置 #endif } protected void Application_BeginRequest( object sender, EventArgs e) { } protected void Application_End( object sender, EventArgs e) { Brotli.Brolib.FreeLibrary(); } protected void Application_Error( object sender, EventArgs e) { //错误日志记录 } protected void AddCompressSupport(HttpContext context) { Boolean doCompress = true ; String compressMode = System.Web.Configuration.WebConfigurationManager.AppSettings[ "CompressMode" ]; if (!String.IsNullOrEmpty(compressMode)) { Boolean.TryParse(compressMode, out doCompress); } //don't use compress for filehandler if (context.Request.Url.AbsoluteUri.Contains( "FileHandler.ashx" )) return ; if (context.Response.ContentType.IndexOf( "json" , StringComparison.CurrentCultureIgnoreCase) >= 0 || (context.Handler is System.Web.SessionState.IRequiresSessionState) ) { context.Response.Cache.SetCacheability(HttpCacheability.NoCache); context.Response.Cache.SetMaxAge(TimeSpan.Zero); context.Response.Cache.SetExpires( new DateTime(2000, 1, 1)); } if (doCompress) { var app = context.ApplicationInstance; String acceptEncodings = app.Request.Headers.Get( "Accept-Encoding" ); if (!String.IsNullOrEmpty(acceptEncodings)) { System.IO.Stream baseStream = app.Response.Filter; acceptEncodings = acceptEncodings.ToLower(); if (acceptEncodings.Contains( "br" ) || acceptEncodings.Contains( "brotli" )) { app.Response.Filter = new Brotli.BrotliStream(baseStream, System.IO.Compression.CompressionMode.Compress); app.Response.AppendHeader( "Content-Encoding" , "br" ); } else if (acceptEncodings.Contains( "deflate" )) { app.Response.Filter = new System.IO.Compression.DeflateStream(baseStream, System.IO.Compression.CompressionMode.Compress); app.Response.AppendHeader( "Content-Encoding" , "deflate" ); } else if (acceptEncodings.Contains( "gzip" )) { app.Response.Filter = new System.IO.Compression.GZipStream(baseStream, System.IO.Compression.CompressionMode.Compress); app.Response.AppendHeader( "Content-Encoding" , "gzip" ); } } } } protected void Application_PostAcquireRequestState( object sender, EventArgs e) { //压缩Response请求 AddCompressSupport(Context); } |
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· .NET Core 托管堆内存泄露/CPU异常的常见思路
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· DeepSeek R1 简明指南:架构、训练、本地部署及硬件要求
· 没有源码,如何修改代码逻辑?
· NetPad:一个.NET开源、跨平台的C#编辑器
· 面试官:你是如何进行SQL调优的?