什么是webrole在onStart()事件和的Application_Start()事件的Global.asax之间的区别? [英] What's the difference between the webrole onStart() event and Application_Start() global.asax event?

查看:237
本文介绍了什么是webrole在onStart()事件和的Application_Start()事件的Global.asax之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚开始让我的脚湿学习的Azure的技术细节,所以道歉,如果这是一个愚蠢的问题。

I'm just starting to get my feet wet learning the technical details of Azure, so apologies if this is a silly question.

如果我创建Visual Studio中的云服务项目,并添加一个用于webrole MVC应用程序,在MVC应用程序中,我可以看到WebRole.cs文件。
然而,当我与MVC应用为出发点开始,后来想启用它的Azure,通过右键单击项目并选择添加Windows Azure云服务项目,没有WebRole.cs被创建。

If I create a cloud service project in visual studio and add a webrole for an mvc application, within the mvc application I can see the "WebRole.cs" file. However, when I start with an MVC application as the starting point, and later want to enable it for Azure, by right clicking on the project and selecting "Add Windows Azure Cloud Service Project", no WebRole.cs is created.

那么,我会去使事情发生在WebRole的启动事件?在Global.asax的的Application_Start()事件文件?

So where would I go to make things happen on the start event of the WebRole? The Application_Start() event of the Global.asax file?

如果是这样,什么是的Application_Start()在Global.asax中和在onStart()一webrole的方法之间的区别?

If so, what's the difference between Application_Start() in Global.asax and the onStart() method of a webrole?

我已经找到了下面的帖子,它提供了部分的解释:
<一href=\"http://stackoverflow.com/questions/6704472/what-starts-first-application-start-or-webroles-onstart\">What开始第一的Application_Start或WebRole的的OnStart?

I've found the following post, which offers a partial explanation: What starts first Application_Start or WebRole's OnStart?

所以,如果它是在WebRole的在onStart事件Global.asax中的Application_Start()之前发生的情况下,如果我想在其上运行在onStart()事件的一些code在一个项目中,我会发生什么后来已经启用了应用程序的Azure的?

So if it's a case that the onStart event of the WebRole occurs before the Application_Start() in Global.asax, what happens if I want to run some code on the onStart() event in a project where I've later enabled the app for Azure?

推荐答案

当有延伸出的类 RoleEntryPoint Web角色的将运行得很好,只是没有额外的code来代替运行的OnStart(),<$ C $的C>运行()和调用OnStop()

When there's no class extending RoleEntryPoint the web role will run just fine, just no extra code is run instead of OnStart(), Run() and OnStop().

的Application_Start()是完全无关的Azure和湛蓝的运行时完全忽略了,它只是一些ASP.NET一块接线。您可以轻松拥有的Application_Start()无条件地抛出一个异常,并不会prevent从开始使用你的Web角色,只是所有HTTP请求都将失败。

Application_Start() is completely unrelated to Azure and is completely ignored by Azure runtime, it's just some piece of ASP.NET wiring. You can easily have Application_Start() unconditionally throwing an exception and that won't prevent your web role from getting started, just all HTTP requests will fail.

请记住与SDK 1.3的默认模式为IIS模式,其中包含 RoleEntryPoint 后裔Web角色的有效载荷在一个进程(WaIISHost.exe),并开始运行ASP.NET code在另一个进程中运行。与 RoleEntryPoint 通过Azure的运行时会首先启动的进程,它运行的OnStart()键,进入无限循环中运行(),那么实例被打开HTTP请求。如果您使用IIS 7.5,并有自动启动启用你可能有的Application_Start()较早执行,否则你不会有的Application_Start()执行,直到第一个请求来了。

Bear in mind that starting with SDK 1.3 the default mode is "IIS mode" where the web role payload containing RoleEntryPoint descendant runs in one process (WaIISHost.exe) and ASP.NET code runs in another process. The process with RoleEntryPoint is started by Azure runtime first, it runs OnStart() and enters the infinite loop in Run(), then the instance is opened for HTTP requests. If you use IIS 7.5 and have "autostart" enabled you may have Application_Start() executed earlier, but otherwise you won't have Application_Start() executed until the first request comes.

因此​​,关键是有正在运行的code两个不同的过程,每个人都有自己的生命周期,并且决定你如何设计应用程序的限制。

So the key is that there're two different processes running your code and each has its own lifetime and that dictates limitations on how you can design your application.

RoleEntryPoint 子类可以有任何名称,属于任何命名空间和位于任意的.cs被选择作为有效载荷为Web角色在项目中的文件 - 这很可能是你的ASP.NET项目。在这些条件下 RoleEntryPoint 后代将由Azure中运行时的定位和它的方法将被作为运行角色实例一生的一部分。

The RoleEntryPoint descendant class can have any name, belong to any namespace and be located in any .cs file within the project which is selected as the payload for the web role - that will likely be your ASP.NET project. Under these conditions the RoleEntryPoint descendant will be located by Azure runtime and its methods will be run as part of role instance lifetime.

这篇关于什么是webrole在onStart()事件和的Application_Start()事件的Global.asax之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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