如何实现Azure Web角色入口点和.aspx页面处理程序在不同的进程中运行?

时间:2011-06-01 13:37:22

标签: windows iis deployment azure cloud

我正在玩this Azure web role sample。它包含一个派生自RoleEntryPoint的类和一个包含按钮单击处理程序的.aspx页面。

我在Azure模拟器中测试它。我把以下代码(采用from here

string userName = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
角色OnStart()和按钮点击处理程序中的

。当调用角色OnStart()时,它恰好在WaIISHost.exe帐户下的MachineName\\MyLogin中运行,当调用按钮处理程序代码时,它恰好在w3wp.exe帐户下MachineName\\NETWORK SERVICE运行。这令人惊讶。

为什么来自同一角色项目的这些代码段在不同的进程内和不同的帐户下运行?我可以改变吗?

2 个答案:

答案 0 :(得分:3)

使用Windows Azure v1.3及更高版本,Web角色利用完整的IIS而不是托管Web Core。 IIS在单独的appdomain中运行。

有关详细信息,请参阅Windows Azure团队中的this blog post

答案 1 :(得分:3)

大卫是对的。除此之外,您可以关闭此行为并在托管的Web核心中运行所有内容(因为它在SDK 1.4之前工作)。您只需要注释服务定义中的“站点”部分,如下例所示:

<?xml version="1.0" encoding="utf-8"?>
<ServiceDefinition name="aExpense.Azure" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition">
  <WebRole name="aExpense" vmsize="Medium">
    <Sites>
      <Site name="Web">
        <Bindings>
          <Binding name="HttpsIn" endpointName="HttpsIn" />
        </Bindings>
      </Site>
    </Sites>
    <ConfigurationSettings>
      <Setting name="DiagnosticsConnectionString" />
      <Setting name="DataConnectionString" />
      <Setting name="allowInsecureRemoteEndpoints" />
    </ConfigurationSettings>