question

ProgrammerBret avatar image
0 Votes"
ProgrammerBret asked

System.ArgumentException: 'Connection string missing required properties endpoint and accesskey. (Parameter 'connectionString')'

This Blazor Server project is a simple chat application using signalR and Azure Active Directory. I am testing locally from my machine before publishing to a server. I am VPN into network. Everything is configured correctly in appsettings.json to point to our Azure test environment, and I have tested successfully with the default Blazor server project against the AAD. However when running the code the following exception is present in Program.cs --

'System.ArgumentException: 'Connection string missing required properties endpoint and accesskey. (Parameter 'connectionString')'

Program.cs:

 public class Program
 {
     public static void Main(string[] args)
     {
         CreateHostBuilder(args).Build().Run();
     }
    
     public static IHostBuilder CreateHostBuilder(string[] args) =>
         Host.CreateDefaultBuilder(args)
             .ConfigureWebHostDefaults(webBuilder =>
             {
                 webBuilder.UseStartup<Startup>();
             });
 }

Startup.cs:

 {
     public Startup(IConfiguration configuration)
     {
         Configuration = configuration;
     }

     public IConfiguration Configuration { get; }

     public void ConfigureServices(IServiceCollection services)
     {
         services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)
             .AddMicrosoftIdentityWebApp(Configuration.GetSection("AzureAd"));
         services.AddControllersWithViews()
             .AddMicrosoftIdentityUI();

         services.AddSignalR().AddAzureSignalR();

         services.AddAuthorization(options =>
         {
             // By default, all incoming requests will be authorized according to the default policy
             options.FallbackPolicy = options.DefaultPolicy;
         });

         services.AddRazorPages();
         services.AddServerSideBlazor()
             .AddMicrosoftIdentityConsentHandler();
         services.AddResponseCompression(opts =>
         {
             opts.MimeTypes = ResponseCompressionDefaults.MimeTypes.Concat(
                 new[] { "application/octet-stream" });
         });
     }

     // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
     public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
     {
         app.UseResponseCompression();

         if (env.IsDevelopment())
         {
             app.UseDeveloperExceptionPage();
         }
         else
         {
             app.UseExceptionHandler("/Error");

             app.UseHsts();
         }

         app.UseHttpsRedirection();
         app.UseStaticFiles();

         app.UseRouting();

         app.UseAuthentication();
         app.UseAuthorization();

         app.UseEndpoints(endpoints =>
         {
             endpoints.MapControllers();
             endpoints.MapBlazorHub();
             endpoints.MapFallbackToPage("/_Host");
             endpoints.MapHub<ChatHub>("/chathub");
         });
     }

The appsettings.json:

 {
   "AzureAd": {
     "Instance": "https://login.microsoftonline.com/",
     "Domain": "university.edu",
     "TenantId": "xxx",
     "ClientId": "xxxx",
     "CallbackPath": "/signin-oidc"
   },
   "Logging": {
     "LogLevel": {
       "Default": "Information",
       "Microsoft": "Warning",
       "Microsoft.Hosting.Lifetime": "Information"
     }
   },
   "Azure": {
     "SignalR": {
       "Enabled": true,
       "ConnectionString": "Connection"
     }
   },
   "AllowedHosts": "*"
 }

Secrets.json:

 {
   "Azure:SignalR:ConnectionString": "Connection"
 }





dotnet-aspnet-generaldotnet-aspnet-core-blazorazure-ad-authentication-protocols
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

0 Answers