不废话,直接贴代码

  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等方法为例子的更多相关文章

  1. 您必须先调用“WebSecurity.InitializeDatabaseConnection”方法,然后再调用"WebSecurity"类的任何其他方法。

    今天调试程序的时候出现了这个是,可惜没截图! 您必须先调用“WebSecurity.InitializeDatabaseConnection”方法,然后再调用"WebSecurity&quo ...

  2. eclipse 中main()函数中的String[] args如何使用?通过String[] args验证账号密码的登录类?静态的主方法怎样才能调用非static的方法——通过生成对象?在类中制作一个方法——能够修改对象的属性值?

    eclipse 中main()函数中的String[] args如何使用? 右击你的项目,选择run as中选择 run configuration,选择arguments总的program argu ...

  3. Odoo(OpenERP) 多个子类重载同一个父类方法的执行顺序及如何调用父类的父类方法

    首先说下起因,在修改英国会计模块(没错,就是那个安格鲁撒克逊记账模式!)中不符合中国国情的部分供能时,碰到了一个棘手的问题,简单的说就是B类继承它的父类A并重载了A的方法M,同时C类也继承了A类也重载 ...

  4. java 子类重写父类的方法应注意的问题

    若想实现一个合格重写方法,而不是重载,那么必须同时满足下面的要求! A.重写规则之一:    重写方法不能比被重写方法限制有更严格的访问级别.(但是可以更广泛,比如父类方法是包访问权限,子类的重写方法 ...

  5. C#中equals方法和==的区别

    Msdn中对equals方法的解释是:确定指定的对象是否等于当前对象. Equals方法是比较对象的内容,而==则是比较整个对象是否相等. Equals方法判断的是堆中的值,而==则判断的是堆栈中的值 ...

  6. 面向对象进阶-类的内置方法 __str__ 、__repr__、__len__、__del__、__call__(三)

    # 内置的类方法 和 内置的函数之间有着千丝万缕的联系# 双下方法# obj.__str__ str(obj)# obj.__repr__ repr(obj) # def __str__(self): ...

  7. python学习之老男孩python全栈第九期_day027知识点总结——反射、类的内置方法

    一. 反射 ''' # isinstance class A:pass class B(A):pass a = A() print(isinstance(a,A)) # 判断对象和类的关系 print ...

  8. Hibernate中get()与load()的区别,以及关于ThreadLocal的使用方法

    一.get方法和load方法的简易理解 (1)get()方法直接返回实体类,如果查不到数据则返回null.load()会返回一个实体代理对象(当前这个对象可以自动转化为实体对象),但当代理对象被调用时 ...

  9. java 子类重写父类的方法

    若想实现一个合格重写方法,而不是重载,那么必须同时满足下面的要求! A.重写规则之一:重写方法不能比被重写方法限制有更严格的访问级别. (但是可以更广泛,比如父类方法是包访问权限,子类的重写方法是pu ...

随机推荐

  1. ArcGIS 图层旋转工具-arcgis案例实习教程

    ArcGIS 图层旋转工具-arcgis案例实习教程 联系方式:谢老师,135-4855-4328,xiexiaokui#qq.com 目的:对输入图层执行坐标旋转 使用方法:输入图层,旋转中心,旋转 ...

  2. 用Nginx+Lua+Redis给百度鹰眼API服务搭建缓存服务中间件(记录过程)

    一.环境安装部分 Centos7,Nginx1.14,Redis5.0,luajit-2.1,ngx_devel_kit-0.3.1rc1,lua-nginx-module-0.10.14. 下载安装 ...

  3. 如何自定义Django数据库中的字段

    新建完项目之后,想要自定义字段 # 创建一个自定义的字段 class MycharField(models.Field): def __inif__(self, max_lenth, *args, * ...

  4. hbase-hive整合及sqoop的安装配置使用

    从hbase中拿数据,然后整合到hbase中 上hive官网  -- 点击wiki--> hive hbase integation(整合) --> 注意整合的时候两个软件的版本要能进行整 ...

  5. Game Engine Architecture 8

    [Game Engine Architecture 8] 1.Differences across Operating Systems • UNIX uses a forward slash (/) ...

  6. 使用Log4J收集日志

    一:搭建好Selenium+testNG+Maven环境,可参考 http://www.cnblogs.com/hc1020/p/8602863.html 二:百度搜索Maven仓库,然后搜索Log4 ...

  7. 关于为什么会涉足easyui

    之前公司需要做一款类似于报价系统的功能,涉及到表单以及报表的统计, 这时分配给我,PHP也要开始弄easyui了 就这样走上了前端的路? 还挺感谢这些时间,有精力来学习额外的东西 不学习就会落后,ヾ( ...

  8. Problem Description——用c语言实现素数的判定

    Problem Description 对于表达式n^2+n+41,当n在(x,y)范围内取整数值时(包括x,y)(-39<=x<y<=50),判定该表达式的值是否都为素数. Inp ...

  9. etcd-v3

    参考:https://www.kancloud.cn/wjx0912/opensource/434745

  10. 512MB内存VPS服务器安装宝塔WEB客户端建站 - 环境部署篇

    原本以为我们很多网友用VPS搭建网站不会用WEB面板,而采用一键包或者自己部署编译环境,但是最后发现其实目前我们使用WEB面板的还是挺多的,无论是免费还是付费的都有不少人使用.比如当初一直免费的AMH ...