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 ...
随机推荐
- mysql 问题:连不上
问题描述: 客户端报错: MySQL Authentication plugin ‘caching_sha2_password’ cannot be loaded 解决方式: ALTER USER ' ...
- rabbitmq和redis用作消息队列的区别
将redis发布订阅模式用做消息队列和rabbitmq的区别: 可靠性redis :没有相应的机制保证消息的可靠消费,如果发布者发布一条消息,而没有对应的订阅者的话,这条消息将丢失,不会存在内存中:r ...
- hive 将一个分区表数据全部插入另外一个分区表
假如现在hive有个分区表A,分区字段为dt 需求是:需要将A表中的数据全部插入到分区表B中 具体步骤如下: 1.create B like A: 2.插入数据 set hive.exec.dynam ...
- web前端学习路线:HTML5教程之前端模块化开发
1. 命名冲突 首先从一个简单的习惯开始. 由于以前一直做 JavaEE 开发的缘故,在 JavaScript 开发中,我已经习惯将项目中的一些通用功能抽象出来,形成一个个的独立函数,以便于实现代码复 ...
- slideDown留言板
<!doctype html> <html lang="en"> <head> <meta http-equiv="Conten ...
- RTP协议全解析(H264码流和PS流)(转)
源: RTP协议全解析(H264码流和PS流)
- Nodejs的npm安装模块时候报错:npm ERR! Error: CERT_UNTRUSTED的解决方法
npm http GET https://registry.npmjs.org/grunt-cli npm http GET https://registry.npmjs.org/grunt-cli ...
- Spring Boot 2(一):Spring Boot 2.0新特性
Spring Boot 2(一):Spring Boot 2.0新特性 Spring Boot依赖于Spring,而Spring Cloud又依赖于Spring Boot,因此Spring Boot2 ...
- ldap集成zabbix
zabbix版本:3.0.7 ldap认证配置: zabbix管理员登录-->管理-->认证,选择ldap方式 参照以上格式填写,需注意配置完成后需在zabbix上创建与ldap同名账户才 ...
- zynq基础-->linux下软件应用
操作系统:Ubuntu 16.04 LTS 应用软件:Vivado 2016.2 + petalinux 2016.2 参考官方应用手册:ug1144-petalinux-tools-referen ...