Asp .net core 1.1 web app publish to azure can't find resource RRS feed

  • Question

  • I just tried to publish my asp .net core web application to Azure and cant get it to work. When I hit browse I get this message

    Picture when I try to browse to my published website

    I've tried to see in the log to figure out what the problem is and found this message

            The specified resource does not exist. RequestId:64038d84-0001-0068-1019-55d321000000 Time:2016-12-13T08:19:53.3494003Z

    I thought it might be the in the 'startup.cs' in the project where I try to find the connection string.

    Github link to project: https://github.com/AlexJCarstensen/ITTWEB-ASPNetCore

    I try to get the connection string link this:

    services.AddDbContext<EmbeddedStockContext>(options =>

    Ive added this setting to Application settings for the app in both App Settings and Connection strings but still it cant find it.

    So the question is how do I get the connectionstring from Azure in its Application settings?

    Info: I'm developing on linux, so dont have access to visual studio.

    Hope you can help

    Regards Alex

    Tuesday, December 13, 2016 1:08 PM

All replies

  • Hello, when you add key values set to App settings, you are basically adding environment variables to your azure web app, so if you want to use configuration APIs, you probably need to add the Environment variables provider

    public class Startup
        public Startup(IHostingEnvironment env)
            var builder = new ConfigurationBuilder()
                .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
                .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
            Configuration = builder.Build();
    this is a code snippet I took from https://docs.microsoft.com/en-us/aspnet/core/fundamentals/configuration where you can find more info on how to use Environment Variables with configuration API 
    Tuesday, December 13, 2016 7:59 PM
  • This is already added in a standard asp .net core web application so that is not the problem.

    I found out when looking in the logs that it I got this error message:

           Application startup exception: System.InvalidOperationException: Could not find 'UserSecretsIdAttribute' on assembly 'ITTWEB-          ASPNetCore

    Whole error message:

    Application startup exception: System.InvalidOperationException: Could not find 'UserSecretsIdAttribute' on assembly 'ITTWEB-ASPNetCore, Version=, Culture=neutral, PublicKeyToken=null'.
       at Microsoft.Extensions.Configuration.ConfigurationExtensions.AddUserSecrets(IConfigurationBuilder configuration)
       at ITTWEB_ASPNetCore.Startup..ctor(IHostingEnvironment env) in D:\home\site\repository\ITTWEB-ASPNetCore\Startup.cs:line 38
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at Microsoft.Extensions.Internal.ActivatorUtilities.ConstructorMatcher.CreateInstance(IServiceProvider provider)
       at Microsoft.Extensions.Internal.ActivatorUtilities.CreateInstance(IServiceProvider provider, Type instanceType, Object[] parameters)
       at Microsoft.Extensions.Internal.ActivatorUtilities.GetServiceOrCreateInstance(IServiceProvider provider, Type type)
       at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.GetServiceOrCreateInstance(IServiceProvider provider, Type type)
       at Microsoft.AspNetCore.Hosting.Internal.StartupLoader.LoadMethods(IServiceProvider hostingServiceProvider, Type startupType, String environmentName)
       at Microsoft.AspNetCore.Hosting.WebHostBuilderExtensions.<>c__DisplayClass1_0.<UseStartup>b__1(IServiceProvider sp)
       at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitFactoryService(FactoryService factoryService, ServiceProvider provider)
       at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(IServiceCallSite callSite, TArgument argument)
       at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProvider provider)
       at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitSingleton(SingletonCallSite singletonCallSite, ServiceProvider provider)
       at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(IServiceCallSite callSite, TArgument argument)
       at Microsoft.Extensions.DependencyInjection.ServiceProvider.<>c__DisplayClass16_0.<RealizeService>b__0(ServiceProvider provider)
       at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType)
       at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
       at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
       at Microsoft.AspNetCore.Hosting.Internal.WebHost.EnsureStartup()
       at Microsoft.AspNetCore.Hosting.Internal.WebHost.EnsureApplicationServices()
       at Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()
    Hosting environment: Production
    Content root path: D:\home\site\wwwroot
    Now listening on: http://localhost:28800
    Application started. Press Ctrl+C to shut down.

    So apparently Azure does not support the ability of UserSecrets. If you want to know more about UserSecrets. Microsoft has some information here:


    In our project we used it to develop on a windows and a linux machine to keep the different connectionstring in a userSecret. And this was not applicable with Azure.

    Hope this helps others.


    Tuesday, December 13, 2016 9:05 PM