AppSettings.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / xsp / System / Web / Util / AppSettings.cs / 1407647 / AppSettings.cs

                            //------------------------------------------------------------------------------ 
// 
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// 
//----------------------------------------------------------------------------- 

// AppSettings.cs 
// 

using System; 
using System.Collections.Specialized;
using System.Web;

namespace System.Web.Util { 

    internal static class AppSettings 
    { 
        private static volatile bool _settingsInitialized = false;
        private static object _appSettingsLock = new object(); 
        private static void EnsureSettingsLoaded() {

            if (!_settingsInitialized) {
                lock (_appSettingsLock) { 
                    if (!_settingsInitialized) {
 
                        NameValueCollection settings = null; 

                        try { 
                            // Check the app-level config. Ignore configuration errors
                            CachedPathData appPathData = CachedPathData.GetApplicationPathData();

                            if (appPathData != null && appPathData.ConfigRecord != null) 
                                settings = appPathData.ConfigRecord.GetSection("appSettings") as NameValueCollection;
                        } finally { 
 
                            // GetApplicationPathData may throw.  That's fine.  Let the user see the exception
                            // once, but just fall back on default settings for the future. 
                            if (settings == null || !Boolean.TryParse(settings["aspnet:UseHostHeaderForRequestUrl"], out _useHostHeaderForRequestUrl))
                                _useHostHeaderForRequestUrl = false;

                            _settingsInitialized = true; 
                        }
                    } 
                } 
            }
        } 

        private static  bool _useHostHeaderForRequestUrl;
        internal static bool UseHostHeaderForRequestUrl {
            get { 
                EnsureSettingsLoaded();
                return _useHostHeaderForRequestUrl; 
            } 
        }
    } 
}

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------------------------ 
// 
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// 
//----------------------------------------------------------------------------- 

// AppSettings.cs 
// 

using System; 
using System.Collections.Specialized;
using System.Web;

namespace System.Web.Util { 

    internal static class AppSettings 
    { 
        private static volatile bool _settingsInitialized = false;
        private static object _appSettingsLock = new object(); 
        private static void EnsureSettingsLoaded() {

            if (!_settingsInitialized) {
                lock (_appSettingsLock) { 
                    if (!_settingsInitialized) {
 
                        NameValueCollection settings = null; 

                        try { 
                            // Check the app-level config. Ignore configuration errors
                            CachedPathData appPathData = CachedPathData.GetApplicationPathData();

                            if (appPathData != null && appPathData.ConfigRecord != null) 
                                settings = appPathData.ConfigRecord.GetSection("appSettings") as NameValueCollection;
                        } finally { 
 
                            // GetApplicationPathData may throw.  That's fine.  Let the user see the exception
                            // once, but just fall back on default settings for the future. 
                            if (settings == null || !Boolean.TryParse(settings["aspnet:UseHostHeaderForRequestUrl"], out _useHostHeaderForRequestUrl))
                                _useHostHeaderForRequestUrl = false;

                            _settingsInitialized = true; 
                        }
                    } 
                } 
            }
        } 

        private static  bool _useHostHeaderForRequestUrl;
        internal static bool UseHostHeaderForRequestUrl {
            get { 
                EnsureSettingsLoaded();
                return _useHostHeaderForRequestUrl; 
            } 
        }
    } 
}

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.

                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK