Imports System.Xml
Imports System.Web
Imports System.IO

Class Helpers
    ' Replicates the functionality of the internal Page.EnableLegacyRendering property 
    Public Shared Function EnableLegacyRendering() As Boolean
        ' 2007-10-02: The following commented out code will NOT work in Medium Trust environments 
        'Configuration cfg = WebConfigurationManager.OpenWebConfiguration(HttpContext.Current.Request.ApplicationPath); 
        'XhtmlConformanceSection xhtmlSection = (XhtmlConformanceSection) cfg.GetSection("system.web/xhtmlConformance"); 

        'return xhtmlSection.Mode == XhtmlConformanceMode.Legacy; 


        ' 2007-10-02: The following work around, provided by Michael Tobisch, works in 
        ' Medium Trust by directly reading the Web.config file as XML. 
        Dim result As Boolean

        Try
            Dim webConfigFile As String = Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, "web.config")
            Dim webConfigReader As New XmlTextReader(New StreamReader(webConfigFile))
            result = ((webConfigReader.ReadToFollowing("xhtmlConformance")) AndAlso (webConfigReader.GetAttribute("mode") = "Legacy"))
            webConfigReader.Close()
        Catch
            result = False
        End Try
        Return result
    End Function
End Class