简体   繁体   English

无法从 Azure App 服务配置应用程序设置中读取 Azure SignalR 连接字符串

[英]Unable to read Azure SignalR Connection String from Azure App Service Configuration Application Settings

I am working on an Azure SignalR application and everything is working fine on my local machine when I set the following section in my appsettings.json:我正在开发一个 Azure SignalR 应用程序,当我在我的 appsettings.json 中设置以下部分时,我的本地计算机上一切正常:

 "Azure": {
    "SignalR": {
      "ConnectionString": "XXXXX"
    }
  }

And then initialize in my startup.cs as follows:然后在我的startup.cs中初始化如下:

services.AddSignalR().AddAzureSignalR();

However when I create the same environment variable in my Azure App Service using App Service>Configration>ApplicationSettings:但是,当我使用 App Service>Configration>ApplicationSettings 在我的 Azure App Service 中创建相同的环境变量时: 在此处输入图像描述

My application is unable to start and I get the following application error:我的应用程序无法启动,并且出现以下应用程序错误:

System.ArgumentException: Connection string missing required properties endpoint and accesskey. (Parameter 'connectionString')
   at Microsoft.Azure.SignalR.ConnectionStringParser.Parse(String connectionString)
   at Microsoft.Azure.SignalR.ServiceEndpoint..ctor(String connectionString, EndpointType type, String name)

When I hardcore my connection string onto the AddAzureSignalR() connectionstring parameter and deploy everything works fine.当我将我的连接字符串硬核到 AddAzureSignalR() connectionstring 参数并部署时,一切正常。

It would seem that azuresignalR is unable to pickup this environment variable, despite also being able to see it via the Kudo Appsettings page as Azure:SginalR:ConnectionString. azuresignalR 似乎无法获取此环境变量,尽管也可以通过 Kudo Appsettings 页面将其视为 Azure:SginalR:ConnectionString。

You need to initiate like this,你需要像这样开始,

 string azureSignalrConnectionString = configuration["Azure:SignalR:ConnectionString"];
 services.AddSignalR().AddNewtonsoftJsonProtocol().AddAzureSignalR(options =>
 {
        options.ConnectionString = azureSignalrConnectionString;
 });

So I asked this same question on the Azure SignalR github page and below was the answer I got:所以我在 Azure SignalR github 页面上问了同样的问题,下面是我得到的答案:

EnvironmentVariablesConfigurationProvider automatically replaces __ with : . EnvironmentVariablesConfigurationProvider 自动将 __ 替换为 : 。 So when you configures connection string via environment variables, you should use Azure__SignalR__ConnectionString as the key.所以当你通过环境变量配置连接字符串时,你应该使用 Azure__SignalR__ConnectionString 作为键。 When you configures it via JSON file, you should use the origin key Azure:SignalR:ConnectionString.通过 JSON 文件对其进行配置时,应使用源密钥 Azure:SignalR:ConnectionString。

Once I changed it to the double underscores all worked一旦我将其更改为双下划线,一切都有效

For.net core 5, use:对于.net core 5,使用:

string azureSignalrConnectionString = Configuration["Azure:SignalR:ConnectionString"];
services.AddSignalR()
        .AddAzureSignalR(options =>
{
     options.ConnectionString = azureSignalrConnectionString;
});

appsettings.json, like: appsettings.json,例如:

{
  "Azure": {
    "SignalR": {
      "ConnectionString": "<your-connection-string>"
    }
  },
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft": "Warning",
      "Microsoft.Hosting.Lifetime": "Information"
    }
  },
  "AllowedHosts": "*"
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Azure App Service上的Wordpress阅读应用程序设置 - Wordpress on Azure App Service read Application settings Azure App Service上的ASP.NET Core无法从应用程序设置中读取连接字符串 - ASP.NET Core on Azure App Service not reading Connection string from Application settings Azure Web 作业无法读取 Azure 应用服务的配置 - Azure Web Jobs unable to read configuration of Azure App Service 部署后,Azure Web Jobs和Azure App Service API是否从相同的“应用程序设置”中读取? - Does Azure Web Jobs and Azure App Service API read from the same “Application Settings” once deployed? Azure 应用服务应用程序设置 - Azure App Service Application settings Azure功能无法读取应用程序设置和连接字符串 - Azure Function unable to read app settings and connection strings 我无法从我的 REACT 应用程序中读取 azure 应用程序服务配置的环境变量 - I am unable to read environment variable from azure app service configuration from my REACT app Azure Function App:我可以将 maxConcurrentSessions 设置放在应用程序设置配置中,如服务总线配置 - Azure Function App: Can I put maxConcurrentSessions settings in Application settings Configuration like service bus configuration HTTPModule 部分的 Azure 应用服务配置设置 - Azure App Service Configuration Settings for HTTPModule section Azure 无法访问存储在应用服务配置中的连接字符串 - Azure cannot access connection string stored in app service configuration
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM