次の方法で共有


Web roles under IIS Classic pipeline mode for backward compatibility

If you have been involved in moving ASP.NET 2.0 Web applications to Windows Azure, you probably have faced some compatibility issues related with the IIS Pipeline mode used by default in a web role.

Windows Azure by default uses integrated mode, but for the sake of simplicity, in some migration scenarios, you could also use Classic mode, that will give you the chance to keep your components as they are.

In order to do that, follow the next steps:

  • You need to add a reference to the library Microsoft.Web.Administration.dll

  • You need to override the OnStart event and add the following code:

     

    Imports System

    Imports System.Collections.Generic

    Imports System.Linq

    Imports Microsoft.WindowsAzure

    Imports Microsoft.WindowsAzure.Diagnostics

    Imports Microsoft.WindowsAzure.ServiceRuntime

    Imports Microsoft.Web.Administration

     

    Public Class WebRole

    Inherits RoleEntryPoint

     

    Public Overrides Function OnStart() As Boolean

     

    'Configure Azure Tracing

    ConfigureTracing()

     

    'Configure Azure Pipeline

    SetClassicIISPipelineMode()

     

    Return MyBase.OnStart()

     

    End Function

    ''' <summary>

    ''' Set IIS Pipeline mode to Classic

    ''' Only use that method when the app needs backward compatibility

    ''' </summary>

    ''' <remarks></remarks>

    Private Sub SetClassicIISPipelineMode()

     

    Dim srvManager As New ServerManager()

     

    Try

    Trace.WriteLine("SetClassicIISPipelineMode starting...")

     

    Dim appSite = (From site In srvManager.Sites

    Where site.Name.Contains(RoleEnvironment.CurrentRoleInstance.Role.Name)).FirstOrDefault()

    If Not appSite Is Nothing Then

    Trace.WriteLine("AppSite reference retreived")

    Dim appPool = (From pool In srvManager.ApplicationPools

    Where pool.Name = appSite.Applications(0).ApplicationPoolName).FirstOrDefault()

    If (Not appPool Is Nothing) Then

    Trace.WriteLine("AppPool reference retreived. Changing mode...")

    appPool.ManagedPipelineMode = ManagedPipelineMode.Classic

    srvManager.CommitChanges()

    Trace.WriteLine("Changes Commited")

    End If

    Else

    Trace.WriteLine("Unable to get AppSite reference")

    End If

     

    Catch ex As Exception

    Trace.WriteLine("SetClassicIISPipelineMode Exception: " + ex.ToString())

    Finally

    srvManager.Dispose()

    End Try

    End Sub

     

     

    Private Sub ConfigureTracing()

    System.Diagnostics.Trace.Listeners.Add(New Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener())

    'The Config is Done using the diagnostics.wadcfg file

    End Sub

     

    End Class

 

And that's it, after these changes, your application will run under IIS classic pipeline mode and you won't have to modify any of your components based on classic pipeline mode.

Comments

  • Anonymous
    September 28, 2011
    Hello Gonzalo, I have tried above code but its not working. The pipeline is still set to integrated mode. Can you upload sample project achieving the same result Regards Shashank

  • Anonymous
    September 28, 2011
    Hello Gonzalo, I have tried above code but its not working. The pipeline is still set to integrated mode. Can you upload sample project achieving the same result Regards Shashank

  • Anonymous
    October 02, 2011
    Hi Shashank , Please be sure that you are deploying to the Management library. Also if you are using multi-sites the following code may change : Dim appSite = (From site In srvManager.Sites Where site.Name.Contains(RoleEnvironment.CurrentRoleInstance.Role.Name)).FirstOrDefault() If you debug the code in the devfabric, are you seeing any error ? Does it work in the Dev Fabric? Regads. Gonzalo.