Connectiestring ophalen

in appsettings.json

{
  "ConnectionStrings": {
    "Connection": "server=xxx;port=xxx;user id=xxx;password=xxx;database=xxx"
  },
  "Logging": {
    "LogLevel": {
      "Default": "Warning"
    }
  },
  "AllowedHosts": "*"
}

in Startup.cs

public class Startup
 {
     public static string Connectionstring { get; private set; } <=== publieke variabele instellen
     public Startup(IConfiguration configuration)
     {
         Configuration = configuration;
     }

     public IConfiguration Configuration { get; }

     public void ConfigureServices(IServiceCollection services)
     {
         ...
     }

     public void Configure(IApplicationBuilder app, IHostingEnvironment env)
     {
         ...

         Connectionstring = Configuration["ConnectionStrings:Connection"]; <=== variable instellen
     }
 }

 

Categories:

Related Article