我在 c# 中使用 .net 和 mvc3。我有一个 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);