Global.asax中的魔法功能 [英] Global.asax magic functions

查看:127
本文介绍了Global.asax中的魔法功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在创建Visual Studio中的ASP.NET MVC项目,一个的Global.asax &安培; 的Global.asax.cs 将被创建。在这个.cs文件,你会发现标准的的Application_Start 方法。

我的问题是下面,怎么叫这个功能呢?因为它不是一个覆盖。所以我的猜测是,这个方法名是惯例。这同样适用于在的Application_Error 方法。

我想知道这些方法是大呼过瘾。因为我写的这些方法(而不是重写它们)我找不到MSDN中对他们的任何文件。 (我发现页面,但它只是告诉你勾到错误事件,显示了的Application_Error(对象发件人,EventArgs五)却不怎么事件和方法链接。)

  // Magicly称为启动
保护无效的Application_Start()
{
    //略
}// Magicly与错误事件挂钩
保护无效的Application_Error(对象发件人,EventArgs的发送)
{
    //略
}


解决方案

这是不是真的神奇.. ASP.NET管道线这一切了。

您可以这里看到对此的文档。

具体来说,你会有兴趣在下面的部分:


  

这是的HttpApplication 对象分配给该请求。


后者包括被解雇,并以什么顺序事件列表中。

有遍布该网页的链接(太多这里含)即关各种其他页面甚至更多的信息联系起来。



  

ASP.NET自动绑定应用程序事件的处理程序
  Global.asax文件使用的命名约定Application_event,如
  为的Application_BeginRequest 。这类似于ASP.NET中的方式
  页方法自动绑定到事件,比如页面的
  的Page_Load 事件。



来源的: http://msdn.microsoft.com/ EN-US /库/ ms178473.aspx

When creating an ASP.NET Mvc project in Visual Studio, a Global.asax & Global.asax.cs will be created. In this .cs file you will find the standard Application_Start method.

My question is the following, how is this function called? because it is not a override. So my guess is that this method name is by convention. The same goes for the Application_Error method.

I want to know where these methods are hooked. Because I write those methods (not override them) I couldn't find any documentation on them in MSDN. (I found this page but it only tells you to hook to the Error event and shows a Application_Error(object sender, EventArgs e) but not how the Event and the method are linked.)

//Magicly called at startup
protected void Application_Start() 
{
    //Omitted
}

//Magicly linked with the Error event
protected void Application_Error(object sender, EventArgs e)
{
    //Omitted
}

解决方案

It isn't really magical.. the ASP.NET Pipeline wires all of this up.

You can see the documentation regarding this here.

Specifically you will be interested in the parts below:

An HttpApplication object is assigned to the request.

Which consists of a list of events that are fired and in what order.

There are links all over that page (too many to contain here) that link off to various other pages with even more information.


ASP.NET automatically binds application events to handlers in the Global.asax file using the naming convention Application_event, such as Application_BeginRequest. This is similar to the way that ASP.NET page methods are automatically bound to events, such as the page's Page_Load event.

Source: http://msdn.microsoft.com/en-us/library/ms178473.aspx

这篇关于Global.asax中的魔法功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆