Esempio n. 1
0
        // GET: AttendeeModels
        public async Task <IActionResult> Index()
        {
            var _dbstring = Config.GetConnectionString("AttendeeContext");

            ViewData["ConnectSource"] = "appsettings.json";
            IConfigurationSection configurationSection = Config.GetSection("ConnectionStrings");

            if (configurationSection != null)
            {
                if (configurationSection.GetValue <string>("AttendeeContext") != null)
                {
                    ViewData["ConnectSource"] = "Config Server";
                }
            }

            var cfe      = new CFEnvironmentVariables();
            var _connect = cfe.getConnectionStringForDbService("user-provided", "AttendeeContext");

            if (!string.IsNullOrEmpty(_connect))
            {
                ViewData["ConnectSource"] = "User Provided Service";
                _dbstring = _connect;
            }

            ViewData["ConnectionString"] = StringCleaner.GetDisplayString("Password="******";", _dbstring, "*****");
            return(View(await _context.AttendeeModel.ToListAsync()));
        }
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddAuthentication(sharedOptions =>
            {
                sharedOptions.DefaultScheme          = CookieAuthenticationDefaults.AuthenticationScheme;
                sharedOptions.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
            })
            .AddAzureAd(options => Configuration.Bind("AzureAd", options))
            .AddCookie();

            services.AddMvc();

            // Use the Bound Service for connection string if it is found in a User Provided Service
            string dbString             = Configuration.GetConnectionString("AttendeeContext");
            CFEnvironmentVariables _env = new CFEnvironmentVariables();
            var _connect = _env.getConnectionStringForDbService("user-provided", "AttendeeContext");

            if (!string.IsNullOrEmpty(_connect))
            {
                Console.WriteLine($"Using bound service connection string for data: {_connect}");
                dbString = _connect;
            }
            else
            {
                Console.WriteLine($"Using connection string from appsetings.json");
            }

            services.AddDbContext <AttendeeContext>(options =>
                                                    options.UseSqlServer(dbString));
        }