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 ...
随机推荐
- jquery中添加元素append,prepend,before和after方法的区别
append:在元素内部的最后面添加元素,作为子元素. prepend:在元素内部的最前面添加元素,作为子元素. before:在元素的前边,作为兄弟元素添加. after:在元素的后边,作为兄弟元素 ...
- 使用phxpaxos开发过程中遇到的坑
1. 开启BatchPropose后,状态机使用ExecuteForCheckpoint生成快照要注意: ExecuteForCheckpoint中的InstanceID不能立即持久化. 例如: 当i ...
- org.apache.hadoop.security.AccessControlException: Permission denied: user=
这个是权限问题,可以配置下,然后重启hadoop集群解决,目前简单的解决方式是: 在 hdfs-site.xml 总添加参数: <property> <name>dfs. ...
- ES6学习笔记(数组)
1.扩展运算符:, 2, 3]) // 1 2 3 console.log(1, ...[2, 3, 4], 5) // 1 2 3 4 5 用于函数调用 function add(x, y) { r ...
- python跨平台注释
使python程序运行在window以外的平台上 !# user/bin/python
- Git简单生成生成公钥和私钥方法
Git简单生成生成公钥和私钥方法 Git配置 Git安装完之后,需做最后一步配置.打开git bash,分别执行以下两句命令 git config --global user.name “用户名” g ...
- JVM学习03:性能监控工具
JVM学习03:性能监控工具 写在前面:本系列分享主要参考资料是 周志明老师的<深入理解Java虚拟机>第二版. 性能监控工具知识要点Xmind梳理 案例分析 案例分析1-JPS 案例分 ...
- 作业四:个人项目-小学四则运算之JAVA版
作业的要求来自于:https://edu.cnblogs.com/campus/gzcc/GZCC-16SE2/homework/2186 代码所在的github远程仓库的地址:https://git ...
- [leetcode]92. Reverse Linked List II反转链表2
Reverse a linked list from position m to n. Do it in one-pass. Note: 1 ≤ m ≤ n ≤ length of list. Exa ...
- 随机获得id的方法
public String generateUUID() { String uuid = UUID.randomUUID().toString(); uuid = uuid.replace(" ...