apolloconfig / apollo.net

Apollo .Net Client
Apache License 2.0
481 stars 167 forks source link

.Net Web API 4.71 下 IConfiguration[key] 不能获取最新配置内容 #110

Closed szg closed 4 years ago

szg commented 4 years ago

image 如图,将 key aaa 从 aoaoao... 更新 为 aoao 后, Configuration[key].value:aoaoao....,AppSetting[key].value:aoao Global 配置如下 public class WebApiApplication : System.Web.HttpApplication { public static IConfiguration Configuration { get; private set; } protected void Application_Start() { GlobalConfiguration.Configure(WebApiConfig.Register);

        Configuration = new Microsoft.Extensions.Configuration.ConfigurationBuilder()
          .AddApollo(ConfigurationManager.AppSettings["Apollo.AppId"], ConfigurationManager.AppSettings["Apollo.MetaServer"])
          .AddDefault()
          .Build();
    }
}

Web.config 配置如下

`

` 获取代码如下 [HttpGet] [Route("api/Apollo/Section/{key}")] public async Task Section(string key) { var config = WebApiApplication.Configuration; //await ApolloConfigurationManager.GetAppConfig(); if (string.IsNullOrEmpty(key)) return await Task.FromResult(null); var value = config[key]; var value2 = ConfigurationManager.AppSettings[key]; return await Task.FromResult($"{nameof(key)}:{key},Configuration[key].value:{value},AppSetting[key].value:{value2}"); }
szg commented 4 years ago

我用 106.54.227.205:8080 测试的就可以,本地Docker 里边 的就不行。

pengweiqhca commented 4 years ago

https://github.com/ctripcorp/apollo.net/blob/dotnet-core/Apollo.Configuration/README.md#43-如何跳过meta-service的服务发现

szg commented 4 years ago

https://github.com/ctripcorp/apollo.net/blob/dotnet-core/Apollo.Configuration/README.md#43-如何跳过meta-service的服务发现

跳过服务发现都是配置过的,也能获取到配置。只是用 ConfigurationManager.AppSettings[key] 能获取到最新的值,但是用IConfiguration[key]获取不到最新值,

pengweiqhca commented 4 years ago

你可以运行Apollo.AspNet.Demo

szg commented 4 years ago

运行之后结果跟我之前发的一致,都是IConfiguration[key]获取不到最新的

szg commented 4 years ago

我 部署方式,按照 https://github.com/ctripcorp/apollo/wiki/Apollo-Quick-Start-Docker%E9%83%A8%E7%BD%B2 一、二,执行。跳过服务发现,appsetting 配置 <add key="Apollo.MetaServer" value="http://192.168.5.133:8080/" /> <add key="Apollo.ConfigServer" value="http://192.168.5.133:8080/" />

pengweiqhca commented 4 years ago

你开启日志看看

Com.Ctrip.Framework.Apollo.Logging.UseConsoleLogging()
szg commented 4 years ago

控制台 程序 没问题的。只有 web下才有这个问题。不太清除原因。但是连接 106.54.227.205:8080 ,也没有配置服务发现 却没有问题。

pengweiqhca commented 4 years ago

看看你是这个问题吗?

szg commented 4 years ago

这个刚也试了,但是我不是这个问题。代码我传 gitee 了,只有 10行代码,希望指正 https://gitee.com/sunnyfish/apollon_test_nfx471

pengweiqhca commented 4 years ago

你的web.config的runtime没有配置正确,请保证编译输出里没有版本重定向输出

szg commented 4 years ago

应该跟这个关系不大吧。json.net 引用版本 apollo.net为 6.0.8,现在随便建个 4.5 项目都是10.0+了,对吧,我用 官网 https://github.com/ctripcorp/apollo.net/blob/dotnet-core/Apollo.AspNet.Demo/Startup.cs#L23 运行我本地 docker apollo 结果跟我 4.7.1 有版本重定向一致,我认为,如果不是 代码的问题的话。可能是 docker 部署的问题,因为,我用你们提供的那个地址 106.54.227.205:8080,IConfiguration[key],AppSetting[key]能得到相同的结果。

szg commented 4 years ago

我关掉了