不废话,直接贴代码

  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. JS数据类型之Number类型

    Number类型的转换及方法 var num = 10; num.toString() //"10"转字符串,参数表示几进制 num.toFixed(2) //10.00 自动舍入 ...

  2. 如何用MATLAB读stl并显示点云文件

    function [VertexData,FVCD,isBinary]=stl2matlab(stlfile) % STL2MATLAB reads STL-file, ASCII or binary ...

  3. k8s之调度约束

    k8s调度约束有两种:第一种,直接指定某台node主机:这种形势将直接跳过调度器.如下: 第二种:先给各node指定标签,然后在通过标签的形势来关联node,这种形势人就会调用到调度器.如下: yao ...

  4. Game Engine Architecture 8

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

  5. vue data中调用图片的相对路径

    直接将图片源文件放在项目目录的static文件夹里,然后和正常写图片路径那样写就可以了,不支持自定义的图片路径

  6. python测试开发django-2.templates模板与html页

    前言 Django 中的视图的概念是一类具有相同功能和模板的网页的集合.通俗一点来说,就是你平常打开浏览器,看到浏览器窗口展示出来的页面内容,那就是视图.前面一章通过浏览器访问http://127.0 ...

  7. openal在vs2010中的配置

    下载openal开发工具:相关资料可以在OpenAL官网http://connect.creativelabs.com/openal/default.aspx上获得.这里下载的SDK为OpenAL11 ...

  8. OJ题解记录计划

    容错声明: ①题目选自https://acm.ecnu.edu.cn/,不再检查题目删改情况 ②所有代码仅代表个人AC提交,不保证解法无误 E0001  A+B Problem First AC: 2 ...

  9. Ireport启动错误

    问题描述:cannot find java.exe Neither (null)\jre\bin\java.exe nor (null)\bin\java.exe exits 解决办法: 打开Irep ...

  10. functools 之 partial(偏函数)

    当函数的参数个数太多,需要简化时,使用functools.partial可以创建一个新的函数,这个新函数可以固定住原函数的部分参数,从而在调用时更简单.当然,decorator(装饰器) 也可以实现, ...