Azure webapp无法读取appsettings.json文件

时间:2018-05-02 15:09:45

标签: azure asp.net-core

最终编辑: 我做了一些改变原始问题的发现。试图找出使用哪个appsettings文件我进入在线App Service Editor并将clientId更改为反映他们所在文件的字符串。我更改了所有appsettings。仍然是相同的错误消息,指出特定的clientID与replyUrl不匹配。 事实是,没有任何appsetting文件包含此cliendId了。所以我开始删除文件后的appsetting文件。每次删除后我重新启动app。仍然是相同的错误消息。即使在那里没有任何appsettings仍然相同的错误消息与相同的ClientId。 因此,我认为Azure可能会遇到一些旧的代码版本,并没有构建任何新的上传。这可以解释这种行为。我做了一个新的应用程序,现在错误消息中的clientId按预期显示appsettings文件中的clientId。 现在我的问题是,是否有一些超级重启功能,因为该网站似乎被卡住了?我想知道它是否再次发生。

原帖:

我有一个使用AzureAD身份验证的.net core 2应用程序。它可以在我的本地计算机上使用AzureAD进行身份验证。但是当访问在线网站时,我收到了这个错误:

  

AADSTS50011:请求中指定的回复网址与为应用程序配置的回复网址不匹配:' 267b122b-b3e7-4ac0-a235-fc3019fc1e49'。

我已经检查了AppRegistration / ReplyURLs及其中的网址   https://siteadress.azurewebsites.net

我还检查了appSettings.json中的applicationId是否正确。

我实际上有相同代码的四个版本。   我公司Azure帐户中的本地和Azure站点。   我自己的测试Azure帐户中的本地和Azure站点。

除了公司帐户上的azure版本外,它们都有效。

此错误消息说回复网址不匹配显示upp我在appsettings.json中放置的内容。我尝试在applicationId,tennantId和domain中部署错误的信息。我已多次尝试并每次都重新启动该网站。不过,我收到此错误消息。所以我得出的结论是appsettings.json没有被网站阅读。

我已经在azure portal中检查了appsettings,它只有DEFAULT_NODE_DEFAULT_VERSION 6.9.2。

appsettings.json文件是正确的。

当我将appsettings.development.json中的applicationID更改为" HelloWorld"并在本地运行该站点,我收到错误,指出没有为应用程序配置匹配的回复URL" HelloWorld"。这样我就可以看到它被阅读了。但不是在天蓝色的网站上。

以下是appSettings.json

的Azure部分中的内容
  "AzureAd": {
    "Instance": "https://login.microsoftonline.com/",
    "GraphInstance": "https://graph.microsoft.com",
    "GraphVersion": "v1.0",
    "Domain": "xxxxx.onmicrosoft.com",
    "TenantId": "xxxx-862d-4076-8aaf-e504b2cdd263",
    "ClientId": "267b122b-b3e7-4ac0-a235-fc3019fc1e49!",
    "ClientSecret": "*******************************",
    "Scopes": "openid email profile offline_access",
    "CallbackPath": "/signin-oidc",
    "BaseUrl": "https://siteadress.azurewebsites.net"
  }

launchSettings.json

    {
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "http://localhost:1940/",
      "sslPort": 44371
    }
  },
  "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "launchUrl": "http://localhost:1940/",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "HiQ_Adress": {
      "commandName": "Project",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      },
      "applicationUrl": "http://localhost:1941/"
    }
  }
}

Startup.cs

public class Startup
{
    public const string ObjectIdentifierType = "http://schemas.microsoft.com/identity/claims/objectidentifier";
    public const string TenantIdType = "http://schemas.microsoft.com/identity/claims/tenantid";

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

    public IConfiguration Configuration { get; }

    // 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.Configure<AzureAdOptions>(Configuration.GetSection("AzureAd"));

        services.AddSingleton<IMyProfileAppService, MyProfileAppService>();
        services.AddSingleton<IAddressAppService, AddressAppService>();
        services.AddSingleton<IAuthenticationHelper, AuthenticationHelper>();
        services.AddSingleton<IAzureAdUserService, AzureAdUserService>();
        services.AddSingleton<IGraphApiClient, GraphApiClient>();

        services.AddMvc();
    }

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
            app.UseBrowserLink();
        }
        else
        {
            app.UseExceptionHandler("/Home/Error");
        }

        app.UseStaticFiles();

        app.UseAuthentication();

        app.UseMvc(routes =>
        {
            routes.MapRoute(
                name: "default",
                template: "{controller=Home}/{action=Index}/{id?}");
            //     template: "{controller=Home}/{action=Index}/{id?}");
        });
    }
}

0 个答案:

没有答案
相关问题