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 ...
随机推荐
- input 标签,不可更改
1.disabled 属性规定应该禁用 input 元素,被禁用的 input 元素,不可编辑,不可复制,不可选择,不能接收焦点,后台也不会接收到传值.设置后文字的颜色会变成灰色.disabled 属 ...
- 基于WebGL架构的3D可视化平台—设备管理
---恢复内容开始--- 国内高层建筑不断兴建,它的特点是高度高.层数多.体量大.面积可达几万平方米到几十万平方米.这些建筑都是一个个庞然大物,高高的耸立在地面上,这是它的外观,而随之带来的内部的建筑 ...
- gitlab 注册runner
个人pc注册runner 注册gitlab-runner ```textPlease enter the gitlab-ci coordinator URL (e.g. https://gitlab. ...
- IIS启动应用程序池报错"服务无法在此时接受控制信息"
用管理员方式打开命令行 输入命令netsh winsock reset 这个命令在百科上的解释是 netsh winsock reset命令,作用是重置 Winsock 目录.如果一台机器上的Wins ...
- 区块链入门(4)Truffle创建项目,编译,及项目部署
上一章的结尾说这一次要讲编写一个智能合约部署到测试网络集群中,并进行交易,但我自己越看越觉得内容挺多的.先讲下truffle的项目创建,编译和部署的问题,然后再做上面说的事情吧. truffle是一套 ...
- C语言之标准头文件模板
/*======================================================================================* * 版权 : xxx ...
- sqlserver 收缩数据库/文件
/******************************/ 1.右键-属性-选项-简单模式 2.右键-任务-收缩-文件 3.右键-任务-收缩-数据库 /********************* ...
- Crane (POJ 2991)
//线段树 延迟标签 // #include <bits/stdc++.h> using namespace std; const int maxn=1e4+5; double x[max ...
- np.where()命令介绍
- iOS socket常用数据类型转换
int -> data /** int -> data */ + (NSData *)intToData:(int)value { Byte byte[4] = {}; byte[0] = ...