发布到azure的Asp .net核心1.1 web应用程序无法找到资源

时间:2016-12-13 08:48:42

标签: asp.net linux azure configuration asp.net-core

我只是尝试将我的asp .net核心Web应用程序发布到Azure,并且无法使其工作。当我点击浏览时,我收到此消息

Picture when I try to browse to my published website

我已经尝试在日志中查看问题是什么并找到此消息

<Error>
  <Code>ResourceNotFound</Code>
    <Message>
        The specified resource does not exist. RequestId:64038d84-0001-0068-1019-55d321000000 Time:2016-12-13T08:19:53.3494003Z
    </Message>
</Error>

我认为这可能是在'startup.cs&#39;在我试图找到连接字符串的项目中。

Github链接到项目:https://github.com/AlexJCarstensen/ITTWEB-ASPNetCore

我尝试获取连接字符串链接:

services.AddDbContext<EmbeddedStockContext>(options =>
   options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));      

我已将此设置添加到应用设置连接字符串中的应用的应用设置,但仍无法找到它。

所以问题是我如何从应用程序设置中获取Azure的连接字符串?

信息:我正在使用linux进行开发,因此无法访问visual studio。

希望你能帮忙

关心Alex

1 个答案:

答案 0 :(得分:0)

在跟进Dmitry评论后,我发现了详细错误消息所在的日志。

错误消息是:

Application startup exception: System.InvalidOperationException: Could     not find 'UserSecretsIdAttribute' on assembly 'ITTWEB-ASPNetCore, Version=1.0.0.0, 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.

显然,Azure不支持UserSecrets的功能。 如果您想了解有关UserSecrets的更多信息。 微软在这里提供了一些信息:

https://docs.microsoft.com/en-gb/aspnet/core/security/app-secrets#security-app-secrets

在我们的项目中,我们使用它在Windows和Linux机器上进行开发,以将不同的连接字符串保存在userSecret中。这不适用于Azure。

希望这有助于其他人。

亚历。