Skip to content

Latest commit

 

History

History
85 lines (71 loc) · 1.53 KB

aspnetcore1.md

File metadata and controls

85 lines (71 loc) · 1.53 KB

Default Builder Settings of Web Host

https://docs.microsoft.com/en-us/aspnet/core/fundamentals/host/web-host

Appsetting.json

{
  "Logging": {
    "LogLevel": {
      "Default": "Debug",
      "Microsoft.AspNetCore": "Debug"
    }
  }
}

Appsetting.json w DummySettings

{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft": "Warning",
      "Microsoft.Hosting.Lifetime": "Information"
    }
  },
 "AllowedHosts": "*", // a sor végére bekerült egy vessző
 "DummySettings": {
   "DefaultString": "My Value",
   "DefaultInt": 23,
   "SuperSecret":  "Spoiler Alert!!!"
 }
}

DummySettings class

public class DummySettings
{
    public string? DefaultString { get; set; }

    public int DefaultInt { get; set; }

    public string? SuperSecret { get; set; }
}

DummySettings config

    builder.Services.Configure<DummySettings>(
        builder.Configuration.GetSection(nameof(DummySettings)));

Get DummySettings injected into DummyController

private DummySettings options;

public DummyController(IOptions<DummySettings> options)
{
    this.options=options.Value;
}

DummySettings.Get getting data from IOption

[HttpGet("{id}", Name = "Get")]
public string Get(int id)
{
    return id % 2 == 0 ? (options.DefaultString ?? "value") : options.DefaultInt.ToString();
}

secrets.json

{
  "DummySettings": {
    "DefaultString": "My Value",
    "DefaultInt": 23,
    "SuperSecret": "SECRET"
  }
}