0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【C# ASP.NET】設定ファイル(appsetting.json)を読み込む方法

Posted at

ASP.NETで設定ファイル(appsetting.json)を読み込む設定について記載します。

Nugetパッケージのインストール

つぎは、設定ファイルを読みこむソースです。

フィールド値「private readonly string _connectString;」を追加し、コンストラクタで呼び出すようにすれば完成です。

sample.cs
public class HomeController : Controller
{
    private readonly ILogger<HomeController> _logger;
    private readonly BookContext _context;
    private readonly string _connectString;

    public HomeController(ILogger<HomeController> logger, BookContext context,IConfiguration configuration)
    {
        _logger = logger;
        this._context = context;
        _connectString = configuration.GetConnectionString("PostgreSqlConnection");
    }
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?