【发布时间】:2012-11-28 12:37:03
【问题描述】:
我正在尝试继承一个基础 global.asax 类来创建我的自定义 global.asax 类。但是我的客户继承的全局类不能正常工作。它的 Application_Start 不会被调用。
有人知道乳清吗?
public class BaseGlobal : HttpApplication
{
protected void Application_Start(Object sender, EventArgs e)
{
log4net.Config.XmlConfigurator.Configure();
Logger.Warn("Portal Started"); //I can find it log file
}
......
}
public class MyGlobal : BaseGlobal
{
new protected void Application_Start(Object sender, EventArgs e)
{
base.Application_Start(sender,e);
Logger.Warn("Portal Started 2"); // Can not find it in log file
}
}
<%@ Application Codebehind="Global.asax.cs" Inherits="Membership_ABC.MyGlobal" Language="C#" %>
在日志文件中,我找不到“Portal started 2”,而只是“Portal Started”。
有什么想法吗?
【问题讨论】:
-
这可以编译吗? “新受保护”似乎很奇怪,我认为应该欢迎覆盖关键字
-
似乎有人在 上打了
new关键字以关闭编译器。嗯,这就是问题所在。 -
AlexH - 你完全正确。 “新修饰符”隐藏了子类中的父代码。 msdn.microsoft.com/en-us/library/435f1dw2.aspx
-
usr 不要认为“新”是造成这种情况的原因。使用 'new' 只是为了让 VS 静音。
-
@ValidfroM 这正是我所说的!您使 VS 静音,从而引入了一个错误。在应用之前阅读“新”的作用!
标签: c# asp.net global-asax