當前位置: 首頁>>代碼示例>>C#>>正文


C# WebConfigurationManager.OpenMappedWebConfiguration方法代碼示例

本文整理匯總了C#中System.Web.Configuration.WebConfigurationManager.OpenMappedWebConfiguration方法的典型用法代碼示例。如果您正苦於以下問題:C# WebConfigurationManager.OpenMappedWebConfiguration方法的具體用法?C# WebConfigurationManager.OpenMappedWebConfiguration怎麽用?C# WebConfigurationManager.OpenMappedWebConfiguration使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Web.Configuration.WebConfigurationManager的用法示例。


在下文中一共展示了WebConfigurationManager.OpenMappedWebConfiguration方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: CreateFileMap

// Utility to map virtual directories to physical ones.
        // In the current physical directory maps 
        // a physical sub-directory with its virtual directory.
        // A web.config file is created for the
        // default and the virtual directory at the appropriate level.
        // You must create a physical directory called config at the
        // level where your app is running.
        static WebConfigurationFileMap CreateFileMap()
        {

            WebConfigurationFileMap fileMap =
                   new WebConfigurationFileMap();

            // Get he physical directory where this app runs.
            // We'll use it to map the virtual directories
            // defined next. 
            string physDir = Environment.CurrentDirectory;

            // Create a VirtualDirectoryMapping object to use
            // as the root directory for the virtual directory
            // named config. 
            // Note: you must assure that you have a physical subdirectory
            // named config in the curremt physical directory where this
            // application runs.
            VirtualDirectoryMapping vDirMap = 
                new VirtualDirectoryMapping(physDir + "\\config", true);

            // Add vDirMap to the VirtualDirectories collection 
            // assigning to it the virtual directory name.
            fileMap.VirtualDirectories.Add("/config", vDirMap);

            // Create a VirtualDirectoryMapping object to use
            // as the default directory for all the virtual 
            // directories.
            VirtualDirectoryMapping vDirMapBase =
                new VirtualDirectoryMapping(physDir, true, "web.config");

            // Add it to the virtual directory mapping collection.
            fileMap.VirtualDirectories.Add("/", vDirMapBase);

# if DEBUG  
            // Test at debug time.
            foreach (string key in fileMap.VirtualDirectories.AllKeys)
            {
                Console.WriteLine("Virtual directory: {0} Physical path: {1}",
                fileMap.VirtualDirectories[key].VirtualDirectory, 
                fileMap.VirtualDirectories[key].PhysicalDirectory);
            }
# endif 

            // Return the mapping.
            return fileMap;
        }
開發者ID:.NET開發者,項目名稱:System.Web.Configuration,代碼行數:53,代碼來源:WebConfigurationManager.OpenMappedWebConfiguration

示例2: OpenMappedWebConfiguration1

// Show how to use the OpenMappedWebConfiguration(
// WebConfigurationFileMap, string)
static void OpenMappedWebConfiguration1()
{

    // Create the configuration directories mapping.
    WebConfigurationFileMap fileMap = 
        CreateFileMap();

    try
    {

        // Get the Configuration object for the mapped
        // virtual directory.
        System.Configuration.Configuration config =
            WebConfigurationManager.OpenMappedWebConfiguration(fileMap, 
            "/config");

        // Define a nique key for the creation of 
        // an appSettings element entry.
        int appStgCnt = config.AppSettings.Settings.Count;
        string asName = "AppSetting" + appStgCnt.ToString();

        // Add a new element to the appSettings.
        config.AppSettings.Settings.Add(asName,
            DateTime.Now.ToLongDateString() + " " +
            DateTime.Now.ToLongTimeString());

        // Save to the configuration file.
        config.Save(ConfigurationSaveMode.Modified);
      
        // Display new appSettings.
        Console.WriteLine("Count:  [{0}]", config.AppSettings.Settings.Count);
        foreach (string key in config.AppSettings.Settings.AllKeys)
        { 
            Console.WriteLine("[{0}] = [{1}]", key, 
                config.AppSettings.Settings[key].Value);
        }
    }
    catch (InvalidOperationException err)
    {
        Console.WriteLine(err.ToString());
    }

    Console.WriteLine();
}
開發者ID:.NET開發者,項目名稱:System.Web.Configuration,代碼行數:46,代碼來源:WebConfigurationManager.OpenMappedWebConfiguration

示例3: OpenMappedWebConfiguration2

// Show how to use the OpenMappedWebConfiguration(
// WebConfigurationFileMap, string, string).
static void OpenMappedWebConfiguration2()
{

    // Create the configuration directories mapping.
    WebConfigurationFileMap fileMap =
        CreateFileMap();

    try
    {

        // Get the Configuration object for the mapped
        // virtual directory.
        System.Configuration.Configuration config = 
            WebConfigurationManager.OpenMappedWebConfiguration(
            fileMap, "/config", "config");
        
        // Define a nique key for the creation of 
        // an appSettings element entry.
        int appStgCnt = config.AppSettings.Settings.Count;
        string asName = "AppSetting" + appStgCnt.ToString();

        // Add a new element to the appSettings.
        config.AppSettings.Settings.Add(asName,
            DateTime.Now.ToLongDateString() + " " +
            DateTime.Now.ToLongTimeString());

        // Save to the configuration file.
        config.Save(ConfigurationSaveMode.Modified);

        // Display new appSettings.
        Console.WriteLine("Count:  [{0}]", 
            config.AppSettings.Settings.Count);
        foreach (string key in config.AppSettings.Settings.AllKeys)
        {
            Console.WriteLine("[{0}] = [{1}]", key,
                config.AppSettings.Settings[key].Value);
        }
    }
    catch (InvalidOperationException err)
    {
        Console.WriteLine(err.ToString());
    }

    Console.WriteLine();
}
開發者ID:.NET開發者,項目名稱:System.Web.Configuration,代碼行數:47,代碼來源:WebConfigurationManager.OpenMappedWebConfiguration

示例4: OpenMappedWebConfiguration3

// Show how to use the OpenMappedWebConfiguration(
// WebConfigurationFileMap, string, string, string).
static void OpenMappedWebConfiguration3()
{

    // Create the configuration directories mapping.
    WebConfigurationFileMap fileMap =
        CreateFileMap();

    try
    {

        // Get the Configuration object for the mapped
        // virtual directory.
        System.Configuration.Configuration config =
            WebConfigurationManager.OpenMappedWebConfiguration(
            fileMap, "/config", "config", "config");

        // Define a nique key for the creation of 
        // an appSettings element entry.
        int appStgCnt = config.AppSettings.Settings.Count;
        string asName = "AppSetting" + appStgCnt.ToString();

        // Add a new element to the appSettings.
        config.AppSettings.Settings.Add(asName,
            DateTime.Now.ToLongDateString() + " " +
            DateTime.Now.ToLongTimeString());

        // Save to the configuration file.
        config.Save(ConfigurationSaveMode.Modified);

        // Display new appSettings.
        Console.WriteLine("Count:  [{0}]", 
            config.AppSettings.Settings.Count);
        foreach (string key in config.AppSettings.Settings.AllKeys)
        {
            Console.WriteLine("[{0}] = [{1}]", key,
                config.AppSettings.Settings[key].Value);
        }
    }
    catch (InvalidOperationException err)
    {
        Console.WriteLine(err.ToString());
    }

    Console.WriteLine();
}
開發者ID:.NET開發者,項目名稱:System.Web.Configuration,代碼行數:47,代碼來源:WebConfigurationManager.OpenMappedWebConfiguration


注:本文中的System.Web.Configuration.WebConfigurationManager.OpenMappedWebConfiguration方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。