小编Łuk*_*ski的帖子

ASP.NET Core 应用程序不从输出目录读取 appsettings.json,而是从项目之一读取 appsettings.json

当涉及 ASP.NET Core 时,我遇到了一种我不理解的行为。

在使用控制台应用程序以读取配置文件时,我通过以下方式将其复制到输出目录:

 <ItemGroup>
      <Content Include="mysettings.json">
        <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      </Content>
    </ItemGroup>
Run Code Online (Sandbox Code Playgroud)

FileNotFoundException否则,如果我只使用文件名而不是完整路径,我就会得到。这样我就可以从其他项目导入文件(例如另一个设置 jsons)并且工作正常。

到目前为止,一切都很好。

但是,在 ASP.NET Core 中(更具体地说,我使用 ASP.NET Core 后端处理 Blazor Web Assembly 项目),当我运行服务器项目时,不会从输出目录中读取设置,而是从项目目录中读取设置。因此,我在尝试从解决方案中的另一个项目读取设置文件时遇到错误,因为应用程序在项目文件夹而不是输出文件夹中查找它。

我不确定它是否相关,但Directory.GetCurrentDirectory()显示/BlazorApp/Server了我宁愿期待的/BlazorApp/Server/bin/Debug/netcoreapp3.1

这是 ASP.NET Core 中的预期行为吗?如果是这样,我如何使用其他项目的文件?我想避免手动更新多个位置的设置。

提前致谢

c# asp.net-core blazor blazor-server-side

4
推荐指数
1
解决办法
5666
查看次数

.NET Core - HTTPClient - Ubuntu 20.04 上的 dh 密钥太小

我想问一下是否有办法绕过 Ubuntu 的安全检查,以便我能够在我的 .NET Core 客户端应用程序中使用一个小密钥来获取网站?我得到了error:141A318A:SSL routines:tls_process_ske_dhe:dh key too small例外。

问题是在 Ubuntu 20.04 中,openSSL 的安全级别设置为2和(目前,希望有人能回答我关于 Ask Ubuntu 的问题)我不知道如何将其设置为较低的值。

使用curlunless--ciphers 'DEFAULT:!DH'参数会发生同样的错误,所以我假设问题的根本原因在于操作系统本身。

我不控制网站的服务器,因此更改其安全设置是不行的。

到目前为止我从 C# 方面尝试过的:

serviceCollection.AddHttpClient<IInterface, IImplementation>()
                             .ConfigureHttpMessageHandlerBuilder(messageHandlerBuilder =>
                             {
                                 messageHandlerBuilder.PrimaryHandler = new HttpClientHandler
                                 {
                                     ServerCertificateCustomValidationCallback = (m, c, ch, e) => true
                                 };
                             });
Run Code Online (Sandbox Code Playgroud)

using var httpClient = new HttpClient();
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;

var …
Run Code Online (Sandbox Code Playgroud)

c# ubuntu openssl dotnet-httpclient .net-core

1
推荐指数
1
解决办法
3889
查看次数