[英]Where are the life cycle events of ASP.Net declared? (NOT the event handlers)
I have an ASP.Net MVC application.我有一个 ASP.Net MVC 应用程序。 Inside there is the famous Global.asax (I didn't touch it):
里面有大名鼎鼎的Global.asax(我没碰):
public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
}
Now, people said this is the event which is being fired when the application starts.现在,人们说这是应用程序启动时触发的事件。 I'm sorry but what I see here is not an event - This is a method.
很抱歉,但我在这里看到的不是事件 - 这是一种方法。 I believe there is an event somewhere that is being fired, and is pointing on this METHOD (so this method is an event handler. Am I wrong?)
我相信某处有一个事件正在被触发,并且指向这个方法(所以这个方法是一个事件处理程序。我错了吗?)
My Q is where is the event itself?我的 Q 是事件本身在哪里? I looked for it in all the solution and didn't find it.
我在所有解决方案中寻找它并没有找到它。
Well after getting the stack trace the leads to the call to Application_Start,I found it was like在获得堆栈跟踪导致对 Application_Start 的调用之后,我发现它就像
at WebApplication1.MvcApplication.Application_Start() in C:\Users\Elite\source\repos\WebApplication2\WebApplication1\Global.asax.cs:line 16
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
at System.Web.HttpApplication.InvokeMethodWithAssert(MethodInfo method, Int32 paramCount, Object eventSource, EventArgs eventArgs)
at System.Web.HttpApplication.ProcessSpecialRequest(HttpContext context, MethodInfo method, Int32 paramCount, Object eventSource, EventArgs eventArgs, HttpSessionState session)
at System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app)
at System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers)
at System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context)
at System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context)
at System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext)
This link contains the source code for the whole thing,这个链接包含整个事情的源代码,
private MethodInfo _onStartMethod;
You are probably interested in the above field, it gets set in this method , if u would spend a couple of minutes with this code u will find that what MVC is doing is scanning for methods existing in the global.ascx file (which is actually a class inheriting HttpApplication class) using reflection of course您可能对上述字段感兴趣,它在此方法中设置,如果您花几分钟使用此代码,您会发现 MVC 正在做的是扫描 global.ascx 文件中存在的方法(实际上是一个继承 HttpApplication 类的类)当然使用反射
Also if you observed the stack trace , u will find a call to the method RegisterEventSubscriptionsWithIIS
, which I am guessing is the answer to your question:"where does events come from"此外,如果您观察堆栈跟踪,您会发现对方法
RegisterEventSubscriptionsWithIIS
的调用,我猜这就是您问题的答案:“事件从何而来”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.