1

私は mvc3 で c# で .net を使用しています。Web.Config 設定があります。

>の値を取得する必要があります<add key="sitelocalization" value="en-GB" /

次のコードでは、このエラーが発生します。

String reference not set to an instance of a String.
Parameter name: name

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.ArgumentNullException: String reference not set to an instance of a String.
Parameter name: name

この行で Thread.CurrentThread.CurrentUICulture = new CultureInfo(localization);


<appSettings>
    <add key="webpages:Enabled" value="false" />
    <add key="sitelocalization" value="en-GB" />
</appSettings>


        string localization = WebConfigurationManager.AppSettings["sitelocalization"];
        Thread.CurrentThread.CurrentUICulture = new CultureInfo(localization);
        Thread.CurrentThread.CurrentCulture = new CultureInfo(localization);
4

2 に答える 2

1

System.Configuration.ConfigurationManager.AppSettings["sitelocalization"] で試してください

于 2013-01-17T07:55:28.120 に答える
0
System.Configuration.Configuration rootWebConfig1 =
                System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(null);
            if (rootWebConfig1.AppSettings.Settings.Count > 0)
            {
                System.Configuration.KeyValueConfigurationElement customSetting = 
                    rootWebConfig1.AppSettings.Settings["customsetting1"];
                if (customSetting != null)
                    Console.WriteLine("customsetting1 application string = \"{0}\"", 
                        customSetting.Value);
                else
                    Console.WriteLine("No customsetting1 application string");
            }




<appSettings>
  <add key="customsetting1" value="Some text here"/>
</appSettings>
于 2013-01-17T07:59:26.293 に答える