gpt4 book ai didi

asp.net - Asp .net core 1.1 网络应用程序发布到 azure 找不到资源

转载 作者:太空宇宙 更新时间:2023-11-04 12:38:00 35 4
gpt4 key购买 nike

我刚刚尝试将我的 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")));

我在应用程序设置连接字符串 中为该应用程序的应用程序设置 添加了此设置,但它仍然找不到它。

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

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

希望能帮到你

问候亚历克斯

最佳答案

在跟进 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://learn.microsoft.com/en-gb/aspnet/core/security/app-secrets#security-app-secrets

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

希望这对其他人有帮助。

亚历克斯。

关于asp.net - Asp .net core 1.1 网络应用程序发布到 azure 找不到资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41116870/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com