【问题标题】:Asp .net core 1.1 web app publish to azure can't find resourceAsp .net core 1.1 web app发布到天蓝色找不到资源
【发布时间】:2017-04-28 06:20:45
【问题描述】:

我刚刚尝试将我的 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”中。

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

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

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

我已在 App SettingsConnection strings 中将此设置添加到该应用的 Application settings 中,但仍然找不到它。

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

信息:我在 linux 上开发,所以无法访问 Visual Studio。

希望你能帮忙

问候亚历克斯

【问题讨论】:

  • Azure 在您的站点“之前”使用 IIS。您有 web.config 以及有关 IIS 的说明。在此处启用日志记录 (stdoutLogEnabled="true") - 这会将 Kestrel 的所有标准输出转储到文件中(路径也在 web.config 中)。然后检查此日志以了解确切的错误。您可以为这两个任务使用 azure 预安装的 kudo
  • 谢谢!发现 azure 可能不支持“builder.AddUserSecrets”或至少这是错误消息。所以知道它有效.. 现在我只需要弄清楚如何在数据库上运行迁移。

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


【解决方案1】:

在跟进 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。

希望这对其他人有所帮助。

亚历克斯。

【讨论】:

  • Azure 支持 UserSecrets,但在本地运行或在 Azure 中运行是有区别的。本地站点有效,因为您有 project.jsonuserSecretId。在 Azure 中,发布不会将其包含在输出中 (issue 62)。并且通过重大更改修复了错误(请参阅announce 209
猜你喜欢
  • 1970-01-01
  • 2018-05-16
  • 1970-01-01
  • 2019-09-29
  • 1970-01-01
  • 1970-01-01
  • 2020-03-30
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多