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 ...
随机推荐
- python之小数据池
代码块 Python 程序 是由代码块构造的.块是一个python程序的文本,它是作为一个执行单元的. 代码块:一个模块,一个函数,一个类,一个文件等都是一个代码块. 而作为交互方式输入的每个命令都是 ...
- 收音机FM和AM的区别
1.频率区别 FM = Frequency Modulation 调频,微波:微波传输,信号质量高,传输成本低,发射功率小,覆盖范围小,受地理因素影响较大,一般作为城市广播的首选.比如你的家乡城市台, ...
- 阿里云部署Java web项目
林炳文Evankaka原创作品.转载请注明出处http://blog.csdn.net/evankaka 摘要:本文主要讲了如何在阿里云上安装JDK.Tomcat以及其配置过程.最后以一个实例来演示在 ...
- 不懂RPC实现原理怎能实现架构梦
RPC(Remote Procedure Call Protocol)——远程过程调用协议,它是一种通过网络从远程计算机程序上请求服务,而不需要了解底层网络技术的协议.RPC协议假定某些传输协议的存在 ...
- log4j2笔记 #03# PatternLayout
该类的目标是格式化LogEvent并返回(字符串)结果.结果的格式取决于具体的模式字符串(pattern string).这里的模式字符串与c语言中printf函数的转换模式非常相似.模式字符串由“转 ...
- linux+apache+nginx实现,反向代理动静分离
在我们开发的过程中,一定会遇到,负载均衡方面的问题.下面我们,做一个小例子:使用nginx+apache实现反向代理,动静分离. 这里apache.php.nginx的安装就不做赘述了,不懂的朋友可以 ...
- 通过RMAN 识别失败数据库损坏的对象
背景 业务起不来,读取数据库时报坏块,无法读取数据 数据库版本:11.2.0.3 数据库无备份,无归档 1. 识别坏块 执行以下命令后,rman 会把坏块信息统计到 v$database_block_ ...
- 深入理解softmax函数
Softmax回归模型,该模型是logistic回归模型在多分类问题上的推广,在多分类问题中,类标签 可以取两个以上的值.Softmax模型可以用来给不同的对象分配概率.即使在之后,我们训练更加精细 ...
- php 采集爬取单个淘宝商品描述,商品属性
下载链接:https://download.csdn.net/download/a724008158/10723448 效果图:
- DDos攻击的常见方法及防御方法
什么是DDoS? DDoS是英文Distributed Denial of Service的缩写,意即“分布式拒绝服务”,那么什么又是拒绝服务(Denial of Service)呢?可以这么理解,凡 ...