asp.net 抽象方法和虚方法的用法区别,用Global类重写Application_BeginRequest等方法为例子
不废话,直接贴代码
public abstract class LogNetGlobal : System.Web.HttpApplication
{
protected void Application_Start()
{
Application_Start_();
}
//public static void RegisterRoutes(RouteCollection routes)
//{
// InitRoutes.SetStaticConfig(".html");
// InitRoutes ir = new InitRoutes(routes);
// ir.LoadRoutes(null);
//}
public void Application_BeginRequest(object sender, EventArgs e)
{
Application_BeginRequest_(sender, e);
LogNet.LogNetHttpContext.Items.AddBeginTime();
} public void Application_EndRequest(object sender, EventArgs e)
{
#region 将请求信息存入日志 string url = Request.Url.AbsoluteUri;
if (!url.ToLower().Contains("testpostjson.aspx") && !url.ToLower().Contains("readlog.aspx"))
{
LogNet.Log.WriteLog(Request);
}
#endregion
Application_EndRequest_(sender, e);
}
public void Application_Error(object sender, EventArgs e)
{
HttpApplication httpApp = sender as HttpApplication;
if (httpApp != null && httpApp.Context != null && httpApp.Context.Error != null)
{
LogNet.Log.WriteLog(httpApp.Context.Error);
}
Application_Error_(sender, e);
} /// <summary>
/// 抽象方法不能有方法体,子类必须要重写该方法
/// </summary>
protected abstract void Application_Start_();
/// <summary>
/// 虚方法一定要有方法体,子类可以选择重写该方法,可以通过base.Application_BeginRequest_(sender,e)的方式调用该基方法
/// </summary>
protected virtual void Application_BeginRequest_(object sender, EventArgs e) { }
protected virtual void Application_EndRequest_(object sender, EventArgs e) { }
protected virtual void Application_Error_(object sender, EventArgs e) { }
} // 注意: 有关启用 IIS6 或 IIS7 经典模式的说明,
// 请访问 http://go.microsoft.com/?LinkId=9394801
public class MvcApplication : LogNetGlobal
{
protected override void Application_Start_()
{
AreaRegistration.RegisterAllAreas();
// RegisterRoutes(RouteTable.Routes); ViewEngines.Engines.Clear();
ViewEngines.Engines.Insert(, new BaseRazorViewEngine()); WebApiConfig.Register(GlobalConfiguration.Configuration);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
AuthConfig.RegisterAuth(); OAWebLib.InPack myInpack = new OAWebLib.InPack();
myInpack.Params.AddString("conn_string", Config.OADsn);
OAWebLib.OACore.InitialCore(myInpack, OAWebLibFunc.Instance);
Config.Init_Config();
Config.is_open_tj = false; Global_Config.InitConfig();
}
public static void RegisterRoutes(RouteCollection routes)
{
InitRoutes.SetStaticConfig(".html");
InitRoutes ir = new InitRoutes(routes);
ir.LoadRoutes(null);
}
protected override void Application_BeginRequest_(object sender, EventArgs e)
{
base.Application_BeginRequest_(sender, e); } protected override void Application_EndRequest_(object sender, EventArgs e)
{
}
protected override void Application_Error_(object sender, EventArgs e)
{
HttpApplication httpApp = sender as HttpApplication;
if (httpApp != null && httpApp.Context != null && httpApp.Context.Error != null)
{
LogNet.Log.WriteLog(httpApp.Context.Error);
ClassLoger.Error(httpApp.Context.Error, httpApp.Context.Error.Message);
}
}
}
asp.net 抽象方法和虚方法的用法区别,用Global类重写Application_BeginRequest等方法为例子的更多相关文章
- 您必须先调用“WebSecurity.InitializeDatabaseConnection”方法,然后再调用"WebSecurity"类的任何其他方法。
今天调试程序的时候出现了这个是,可惜没截图! 您必须先调用“WebSecurity.InitializeDatabaseConnection”方法,然后再调用"WebSecurity&quo ...
- eclipse 中main()函数中的String[] args如何使用?通过String[] args验证账号密码的登录类?静态的主方法怎样才能调用非static的方法——通过生成对象?在类中制作一个方法——能够修改对象的属性值?
eclipse 中main()函数中的String[] args如何使用? 右击你的项目,选择run as中选择 run configuration,选择arguments总的program argu ...
- Odoo(OpenERP) 多个子类重载同一个父类方法的执行顺序及如何调用父类的父类方法
首先说下起因,在修改英国会计模块(没错,就是那个安格鲁撒克逊记账模式!)中不符合中国国情的部分供能时,碰到了一个棘手的问题,简单的说就是B类继承它的父类A并重载了A的方法M,同时C类也继承了A类也重载 ...
- java 子类重写父类的方法应注意的问题
若想实现一个合格重写方法,而不是重载,那么必须同时满足下面的要求! A.重写规则之一: 重写方法不能比被重写方法限制有更严格的访问级别.(但是可以更广泛,比如父类方法是包访问权限,子类的重写方法 ...
- C#中equals方法和==的区别
Msdn中对equals方法的解释是:确定指定的对象是否等于当前对象. Equals方法是比较对象的内容,而==则是比较整个对象是否相等. Equals方法判断的是堆中的值,而==则判断的是堆栈中的值 ...
- 面向对象进阶-类的内置方法 __str__ 、__repr__、__len__、__del__、__call__(三)
# 内置的类方法 和 内置的函数之间有着千丝万缕的联系# 双下方法# obj.__str__ str(obj)# obj.__repr__ repr(obj) # def __str__(self): ...
- python学习之老男孩python全栈第九期_day027知识点总结——反射、类的内置方法
一. 反射 ''' # isinstance class A:pass class B(A):pass a = A() print(isinstance(a,A)) # 判断对象和类的关系 print ...
- Hibernate中get()与load()的区别,以及关于ThreadLocal的使用方法
一.get方法和load方法的简易理解 (1)get()方法直接返回实体类,如果查不到数据则返回null.load()会返回一个实体代理对象(当前这个对象可以自动转化为实体对象),但当代理对象被调用时 ...
- java 子类重写父类的方法
若想实现一个合格重写方法,而不是重载,那么必须同时满足下面的要求! A.重写规则之一:重写方法不能比被重写方法限制有更严格的访问级别. (但是可以更广泛,比如父类方法是包访问权限,子类的重写方法是pu ...
随机推荐
- fopen特殊模式r+, w+, a+辨析
fopen模式分两大类,即 TEXT模式:r, w, a, r+, w+, a+ BIN模式:rb, wb, ab, r+b, w+b, a+b 模式 读指针初始位置 写指针初始位置 模式用途 详细说 ...
- 在CentOS6.9 x86下编译libusb-1.0.22遇到的两个问题
OS版本:CentOS 6.9 x86,内核版本2.6.32 问题一:configure.ac:36: error: Autoconf version 2.69 or higher is requir ...
- 移动端目标识别(3)——使用TensorFlow Lite将tensorflow模型部署到移动端(ssd)之Running on mobile with TensorFlow Lite (写的很乱,回头更新一个简洁的版本)
承接移动端目标识别(2) 使用TensorFlow Lite在移动设备上运行 在本节中,我们将向您展示如何使用TensorFlow Lite获得更小的模型,并允许您利用针对移动设备优化 ...
- 深入理解C++11【4】
[深入理解C++11[4]] 1.基于范围的 for 循环 C++98 中需要告诉编译器循环体界面范围.如for,或stl 中的for_each: int main() { ] = { , , , , ...
- Charles篡改后台数据
1.打开Charles找到相对应的接口 2.在接口上右键选择Breakpoints打断点. 3.重新请求截断接口,Charles会多弹出一个截断窗口如下图(第一个修改请求的,第二图是修改返回的) 点击 ...
- base64位代码转图片文件并保存到文件夹的解决方案
#region Base64 转图片方法 protected string Base64StringToImage(string strbase64) { try { string imgurl = ...
- 自己实现ArrayList
思路: 一 载体 ArrayList是一个集合容器,必然要有一个保存数据的载体. public class MyArraylist { private final static int INIT_CO ...
- linux命令——wc
wc 统计文件里面有多少单词,多少行,多少字符. wc语法 [root@www ~]# wc [-lwm] 选项与参数: -l :仅列出行: -w :仅列出多少字(英文单字): -m :多少字符: 默 ...
- PowerScript SQL语句
PowerScript支持在脚本中使用标准的嵌入式SQL和动态SQL语句.还支持在SQL语句中使用数据库管理系统的语句.函数和保留字. 在SQL中任何地点都可以使用常量和任何合法的变量,但使用变量时必 ...
- oracle中的exists 和 in 用法详解
以前一直不知道exists和in的用法与效率,这次的项目中需要用到,所以自己研究了一下.下面是我举两个例子说明两者之间的效率问题. 前言概述: “exists”和“in”的效率问题,涉及到效率问题也就 ...