Global.asax.cs中相关方法
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中相关方法的更多相关文章
- .Global.asax.cs中的方法的含义
Application_Init:在每一个HttpApplication实例初始化的时候执行 Application_Disposed:在每一个HttpApplication实例被销毁之前执行 App ...
- Global.asax.cs 为 /.aspx 执行子请求时出错。 Server.Transfer
x 后台代码 Global.asax.cs protected void Application_Error(object sender, EventArgs e){Server.Transfer(& ...
- Global.asax.cs介绍
转载 http://www.cnblogs.com/tech-bird/p/3629585.html ASP.NET的配置文件 Global.asax--全局应用程序文件 Web.config--基 ...
- 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-> ...
- 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 ...
- <%@ Application Codebehind="Global.asax.cs" Inherits="XXX.MvcApplication" Language="C#" %>
<%@ Application Codebehind="Global.asax.cs" Inherits="XXX.MvcApplication" Lan ...
- asp.net中使用Global.asax文件中添加应用出错代码,写入系统日志文件或数据库
void Application_Error(object sender, EventArgs e) { // 在出现未处理的错误时运行的代码 Exception objErr = Server.Ge ...
- 知识记录:ASP.NET 应用程序生命周期概述及Global.asax文件中的事件
IIS7 ASP.NET 应用程序生命周期概述 https://msdn.microsoft.com/zh-cn/library/bb470252(v=vs.100).aspx HttpApplica ...
- C# Global.asax.cs 定时任务
定时执行更新Redis缓存操作 protected void Application_Start(object sender, EventArgs e) { Timer timer = new Tim ...
随机推荐
- 获取 web 服务器 port
Tomcat: public static String getServerPort(boolean secure) throws AttributeNotFoundException, Instan ...
- tiny4412 硬件解码
今天发现了一个好的资源,上面有三星的一些实例代码.http://git.infradead.org/users/kmpark/public-apps
- 【转】ETL介绍与ETL工具比较
本文转载自:http://blog.csdn.net/u013412535/article/details/43462537 ETL,是英文 Extract-Transform-Load 的缩写,用来 ...
- ClassThree__HomeWork
作业一 使用类的静态字段和构造函数,可以跟踪某个类所创建对象的个数.请写一个类,在任何时候都可以向它查询“你已经创建了多少个对象?”. 代码 public class TestOne { ...
- 20165316 2017-2018-2《Java程序设计》课程总结
20165316 2017-2018-2<Java程序设计>课程总结 一.每周作业链接汇总 1. 预备作业一:我期望的师生关系 20165316 我期望的师生关系 摘要: 典型老师 师生关 ...
- es6基本语法
//let和const申明变量和常量 //作用域只限于当前代码块 //使用let申明的变量作用域不会提升 //在相同的作用域下不能申明相同的变量 //for循环体现let的父子作用域 二.es6的解构 ...
- zabbix agent配置详解(windows)
客户端操作 标注:监控zabbix_agentd客户端安装对象是win server 2008操作系统 64位. 1. 下载zabbix_agentd监控客户端软件安装包(windows操作系统客 ...
- Linux(64) 下 Tomcat + java 环境搭建
查看 linux 系统位数 getconf LONG_BIT java JDK下载地址: http://download.oracle.com/otn-pub/java/jdk/8u181-b13/ ...
- GoldenGate 12.3 MA架构介绍系列(3) - 各功能模块介绍
在新版的ogg 12.3 microservice architect中,提供了4个不同的服务模块和命令行模块. Admin Server: 负责连接用户.trandata, checkpoint的添 ...
- kafka数据可靠传输
再说复制Kafka 的复制机制和分区的多副本架构是Kafka 可靠性保证的核心.把消息写入多个副本可以使Kafka 在发生崩愤时仍能保证消息的持久性. Kafka 的主题被分为多个分区,分区是基本的数 ...