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);
}

  

Global.asax.cs中相关方法的更多相关文章

  1. .Global.asax.cs中的方法的含义

    Application_Init:在每一个HttpApplication实例初始化的时候执行 Application_Disposed:在每一个HttpApplication实例被销毁之前执行 App ...

  2. Global.asax.cs 为 /.aspx 执行子请求时出错。 Server.Transfer

    x 后台代码 Global.asax.cs protected void Application_Error(object sender, EventArgs e){Server.Transfer(& ...

  3. Global.asax.cs介绍

    转载  http://www.cnblogs.com/tech-bird/p/3629585.html ASP.NET的配置文件 Global.asax--全局应用程序文件 Web.config--基 ...

  4. Where is the Global.asax.cs file

    I am using VS 2008. I have created a new Asp.net web site project from File->New->Website-> ...

  5. ASP.NET 调试出现<%@ Application Codebehind="Global.asax.cs" Inherits="XXX.XXX.Global" Language="C#" %>

    ASP.NET 调试出现<%@ Application Codebehind="Global.asax.cs" Inherits="XXX.XXX.Global&q ...

  6. <%@ Application Codebehind="Global.asax.cs" Inherits="XXX.MvcApplication" Language="C#" %>

    <%@ Application Codebehind="Global.asax.cs" Inherits="XXX.MvcApplication" Lan ...

  7. asp.net中使用Global.asax文件中添加应用出错代码,写入系统日志文件或数据库

    void Application_Error(object sender, EventArgs e) { // 在出现未处理的错误时运行的代码 Exception objErr = Server.Ge ...

  8. 知识记录:ASP.NET 应用程序生命周期概述及Global.asax文件中的事件

    IIS7 ASP.NET 应用程序生命周期概述 https://msdn.microsoft.com/zh-cn/library/bb470252(v=vs.100).aspx HttpApplica ...

  9. C# Global.asax.cs 定时任务

    定时执行更新Redis缓存操作 protected void Application_Start(object sender, EventArgs e) { Timer timer = new Tim ...

随机推荐

  1. 计算属性(computed)、方法(methods)和侦听属性(watch)的区别与使用场景

    1,computed 能实现的,methods 肯定也能够实现. 2,不同之处在于,computed 是基于他的依赖进行缓存的,computed 只有在他的的相关依赖发生改变的时候才会重新计算. 如果 ...

  2. python中装饰器修复技术

    python装饰器@wraps作用-修复被装饰后的函数名等属性的改变 Python装饰器(decorator)在实现的时候,被装饰后的函数其实已经是另外一个函数了(函数名等函数属性会发生改变), 为了 ...

  3. CBV源码解析

    1.CBV(class based view) 首先定义一个视图函数,用类的方式定义: 举例: class LoginView(View): def get(self,request): return ...

  4. MongoDB遇到的疑似数据丢失的问题。不要用InsertMany!

    最近做数据备份的时候发现了有个很严重的问题,那就是数据丢失(最后证明没丢,是别的问题造成的). 问题如下: 我通过两种方式在两个mongoDB集群中,对一组collection进行备份,最后2个备份数 ...

  5. linux screen 多任务后台执行

    1.安装工具:yum install -y screen 2.进入新screen界面:screen 3.回到原命令行:先按CTRL+a,然后再按d 4.查看现有的screen回话:screen -ls ...

  6. windows与linux ping 显示的ip不一样

    DNS修改了一下域名对应的IP后,域名不能访问了,我在windows下ping一下域名,IP没有变过来,还是老的IP.我在linux下又ping了一下域名,是换过了的.这个问题是由windows下的本 ...

  7. maven编译项目报错,提示找不到符号或程序包XXX不存在

    我的原因是maven依赖的jar包都下载了,但是引用的同一个项目下其他模块jar包找不到 解决方法: 把需要的jar包在pom里添加依赖 再次运行项目,Maven Dependencies下就会多了几 ...

  8. Linux环境jdk的安装

    1.下载jdk1.7,oracle的下载地址已经失效,找了个其他的地址进行下载. wget http://pc.xzstatic.com/2017/03/jdk7u79linuxx64.tar.gz ...

  9. linux下启动多个php,分别监听不同的端口。

    在工作中,我们可能会遇到,服务器集群的搭建. 这个时候,我们不可能,每一台服务器都是lnmp的环境,我们会把nmp分别放在不同的服务器上,不同的服务器负责不同的功能.比如我们下面要说的php 加入ng ...

  10. chrome platform

    folder_extension: ---menifest.json ---navigator_change.js manifest.json { "manifest_version&quo ...