我有一个要从.Net Framework 4.7.1移植到.Net Core 2.0的库。
我陷入了这段代码:
System.Configuration.Configuration config =
System.Configuration.ConfigurationManager.OpenExeConfiguration(
System.Configuration.ConfigurationUserLevel.None);
System.Net.Configuration.SettingsSection section =
(System.Net.Configuration.SettingsSection)
config.GetSection("system.net/settings");
if(unsafeHttpHeaderParsingUsed == 2)
unsafeHttpHeaderParsingUsed = section.HttpWebRequest.UseUnsafeHeaderParsing ? 1 : 0;
section.HttpWebRequest.UseUnsafeHeaderParsing = enabled;
config.Save();
System.Configuration.ConfigurationManager.RefreshSection("system.net/settings");
我为Microsoft.Extensions.Configuration
下载了各种NuGet软件包,并具有以下代码:
public static IConfiguration Configuration { get; } = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.AddEnvironmentVariables()
.Build();
为此,我已经使用用户设置移植了其他部分,但让我感到困扰的部分是System.Net.Configuration.SettingsSection
。我似乎找不到section.HttpWebRequest.UseUnsafeHeaderParsing
的端口。
当前代码:
var config = bool.Parse(Configuration.GetSection("system.net/settings"));
if (unsafeHttpHeaderParsingUsed == 2)
unsafeHttpHeaderParsingUsed = section.HttpWebRequest.UseUnsafeHeaderParsing ? 1 : 0;
section.HttpWebRequest.UseUnsafeHeaderParsing = enabled;