Blazor Web Assembly 应用程序 .Net Core 托管:发布运行时错误

2024-01-30

我使用 .NET 5.0 RC1 Framework 创建了一个托管在 .NET Core 应用程序内的简单 Blazor Web Assembly 项目,并在 Visual Studio 2019 预览版中的向导过程中添加了授权。它在调试中完美运行,但如果我发布它并尝试连接到服务器,我会收到 500 错误。检查日志错误是:

Microsoft.AspNetCore.Server.Kestrel[13]
      Connection id "0HM37MQFV38CV", Request id "0HM37MQFV38CV:00000003": An unhandled exception was thrown by the application.
      System.NullReferenceException: Object reference not set to an instance of an object.
         at Microsoft.Extensions.DependencyInjection.IdentityServerBuilderConfigurationExtensions.<>c.<AddSigningCredentials>b__10_2(IServiceProvider sp)
         at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitFactory(FactoryCallSite factoryCallSite, RuntimeResolverContext context)
         at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitCache(ServiceCallSite callSite, RuntimeResolverContext context, ServiceProviderEngineScope serviceProviderEngine, RuntimeResolverLock lockType)
         at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache(ServiceCallSite singletonCallSite, RuntimeResolverContext context)
         at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
         at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitIEnumerable(IEnumerableCallSite enumerableCallSite, RuntimeResolverContext context)
         at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitNoCache(ServiceCallSite callSite, TArgument argument)
         at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
         at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, RuntimeResolverContext context)
         at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitDisposeCache(ServiceCallSite transientCallSite, RuntimeResolverContext context)
         at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
         at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, RuntimeResolverContext context)
         at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitDisposeCache(ServiceCallSite transientCallSite, RuntimeResolverContext context)
         at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
         at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, RuntimeResolverContext context)
         at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitDisposeCache(ServiceCallSite transientCallSite, RuntimeResolverContext context)
         at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
         at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, RuntimeResolverContext context)
         at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitDisposeCache(ServiceCallSite transientCallSite, RuntimeResolverContext context)
         at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
         at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, RuntimeResolverContext context)
         at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitDisposeCache(ServiceCallSite transientCallSite, RuntimeResolverContext context)
         at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
         at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.Resolve(ServiceCallSite callSite, ServiceProviderEngineScope scope)
         at Microsoft.Extensions.DependencyInjection.ServiceLookup.DynamicServiceProviderEngine.<>c__DisplayClass1_0.<RealizeService>b__0(ServiceProviderEngineScope scope)
         at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.GetService(Type serviceType, ServiceProviderEngineScope serviceProviderEngineScope)
         at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope.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.Authentication.AuthenticationHttpContextExtensions.AuthenticateAsync(HttpContext context, String scheme)
         at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
         at IdentityServer4.Hosting.BaseUrlMiddleware.Invoke(HttpContext context)
         at Microsoft.AspNetCore.Builder.Extensions.MapWhenMiddleware.Invoke(HttpContext context)
         at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.<Invoke>g__Awaited|6_0(ExceptionHandlerMiddleware middleware, HttpContext context, Task task)
         at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.HandleException(HttpContext context, ExceptionDispatchInfo edi)
         at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.<Invoke>g__Awaited|6_0(ExceptionHandlerMiddleware middleware, HttpContext context, Task task)
         at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication`1 application)

我认为问题与身份服务器和证书有关,但我不明白是什么。

有任何想法吗?

Thanks.


当使用.pfx文件我收到以下错误:

Blazor - app.UseIdentityServer();使用 .pfx 密钥文件 - 解析数字时遇到意外字符 https://stackoverflow.com/questions/66448141/blazor-app-useidentityserver-with-pfx-key-file-unexpected-character-enco

我也使用了这个错误AddDeveloperSigningCredential and AddSigningCredential with services.AddIdentityServer().

具有个人帐户和 ASP.NET Core 托管的 Blazor WebAssembly 应用程序 - 未将对象引用设置为对象的实例 - AddSigningCredentials https://stackoverflow.com/q/69429340/3850405

我最终是这样解决的:

以管理员身份在 Powershell 中创建了一个新证书:

New-SelfSignedCertificate -DnsName "blazortest" -CertStoreLocation "cert:\CurrentUser\My"

应用程序设置.json:

  "IdentityServer": {
    "Clients": {
      "BlazorTest.Client": {
        "Profile": "IdentityServerSPA"
      }
    },
    "Key": {
      "Type": "Store",
      "StoreName": "My",
      "StoreLocation": "CurrentUser",
      "Name": "CN=blazortest"
    }
  },

https://learn.microsoft.com/en-us/aspnet/core/security/authentication/identity-api-authorization?view=aspnetcore-3.0#example-deploy-to-azure-app-service https://learn.microsoft.com/en-us/aspnet/core/security/authentication/identity-api-authorization?view=aspnetcore-3.0#example-deploy-to-azure-app-service

从以下位置删除了此内容appsettings.Development.json:

  "IdentityServer": {
    "Key": {
      "Type": "Development"
    }
  }

这在本地有效。然后我用了mmc.exe将证书导出为.pfx文件并通过上传Azure App Service -> TLS/SSL settings.

然后我用了Azure Cloud Shell启用对证书的访问,如下所示:

az webapp config appsettings set --name <app-name> --resource-group <resource-group-name> --settings WEBSITE_LOAD_CERTIFICATES=<comma-separated-certificate-thumbprints>

https://learn.microsoft.com/en-us/azure/app-service/configure-ssl-certificate-in-code#load-the-certificate-in-code https://learn.microsoft.com/en-us/azure/app-service/configure-ssl-certificate-in-code#load-the-certificate-in-code

您还可以添加Certificate Thumbprint手动添加WEBSITE_LOAD_CERTIFICATES to Configuration:

然后终于成功了!

如果您从 Azure Cloud Shell 收到如下错误:

ResourceGroupNotFound:找不到资源组“”。

确保您处于正确的订阅中,并使用以下命令设置正确的订阅:

az account show

az account list

az account set --subscription <subscriptionId>

如果您托管在IIS你需要导入.pfx证书给Personal文件夹Local Computer然后选择Manage Private Keys...并授予运行该程序的用户访问权限Application Pool.

托管在 GCP、Google Cloud Platform 上,如果您没有上传证书,您可能会看到与此类似的错误。

未处理的异常。 System.InvalidOperationException:找不到 “CurrentUser\My”上主题为“CN=blazortest”的有效证书

Linux 无法使用 Windows 证书存储来加载 TLS 证书,因此需要从文件加载证书:

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Blazor Web Assembly 应用程序 .Net Core 托管:发布运行时错误 的相关文章

随机推荐

  • List集合中的Select方法

    我有一个 asp net 应用程序 现在我正在使用数据集进行数据操作 我最近开始将此数据集转换为列表集合 但是 在某些地方它不起作用 一是在我的旧版本中我正在使用datarow drow dataset datatable select s
  • Ray on slurm - 初始化问题

    我写这篇文章是因为自从我使用 slurm 以来 我一直无法正确使用 ray 每当我使用命令时 ray init trainer A3CTrainer env my env 我已经在tune上注册了我的env 程序崩溃并显示以下消息 core
  • 将facet_wrap分割成多页PDF

    我已经四处寻找解决方案 但似乎大多数处理将单独生成的图合并为 PDF 格式 而不是将使用分面生成的图分离到 PDF 的单独页面上 示例数据 https drive google com file d 0B8KPGzjWWaw7V0s3UG0
  • mysql - 如何连接字符串并将字符串转换为日期?

    请看一下我的存储过程代码 CREATE DEFINER ninjaboy PROCEDURE getMonthlyTotalScore IN ninjaId int IN month int IN year int BEGIN DECLAR
  • Python - 使用defaultdict制作自定义对象的字典

    我创建了以下课程 包 网站和评论都是字符串 distroDict 是一个 string list 字典 class TableEntry object def init self package website distroDict com
  • 在加载和 Ajax 加载的内容上运行 JS 代码

    请看这个 HTML 代码 div class grid h2 First h2 p Second p div div class grid h2 First h2 p Second p div 我可以使用以下代码更改页面加载时元素的顺序 g
  • C++ lambda 函数的默认调用约定是什么?

    下面的代码是用VC 2012编译的 void f1 void stdcall void f2 void cdecl void cdecl h1 void stdcall h2 int main f1 h1 error C2664 f2 h2
  • Azure - 一个“块 blob”是否被视为一个文件?

    问题背景 这可能是一个简单的问题 但我找不到答案 我刚刚开始使用 Azure 存储 用于存储图像 想知道一个 blob 是否最多可容纳一个文件 这是我的容器 名为fmfcpics 在容器内我有一个名为的块 blobmyBlob其中我有一张图
  • CA2227 的解决方案还是更好的方法?

    我仅使用代码分析来清理 组织并确保针对特定警告的所有实例全局执行这些更改 我已经进入决赛了 比赛是 CA2227 CA2227 集合属性应为只读 将 更改为 通过删除属性设置器来只读 请注意 这是用于 EDI 文档的映射 这些类代表 EDI
  • 降落伞分段错误 - pygame 到 py2exe

    我正在使用 GUI2Exe 将我的 python pygame 游戏编译为 exe 我的字体模块有问题 使用 python 2 7 和 GUI2Exe 中的 py2exe 选项 我已经将 python pygame 和 py2exe 更新为
  • Chrome 的 colspan 和 border 错误?

    在下面的示例中 右侧单元格的顶部有一个边框 它只出现在 Chrome 中 是 Chrome 的 bug 吗 HTML CSS html body height 100 table border collapse collapse width
  • 在 Flutter 中重新发送 OTP 代码 Firebase 电话身份验证

    这可能是重复的 但任何其他线程都没有为我提供正确的答案 有关于 android 原生语言的答案 但没有关于 Flutter dart 的答案 我有以下有效方法 但如果我想将 OTP 重新发送到用户电话号码 我该怎么做 只需一个简单的示例代码
  • java jre 7u45 破坏了 classloader.getResources()?

    我有代码迭代 classLoader getResources META INF MANIFEST MF 的结果以返回类路径上的 jar 列表 从 1 6 0 18 一直到 1 7 0 40 这都工作得很好 现在 1 7 0 45 通过显示
  • EF Core Fluent API 配置防止 TPC 继承

    我有相互继承的模型 但我正在努力让流畅的 api 配置按照我想要的方式运行 假设我有一个基类 它定义了一些核心属性 public class Entity public int Id get set public string Title
  • 如何设置 Azure Devops 来构建 Devexpress XAF-XPO 项目?

    我想在 Azure Devops 中为 XAP 移动应用程序设置持续集成和部署 为了获得 CI CD 我需要设置 Azure Pipeline 来安装正确的包 文档中有一些信息托管您自己的 NuGet 源 https learn micro
  • 互换使用 std::string 和 QString

    我在我正在开发的图形和 GUI 组件软件系统中广泛使用 Qt 然而 对于大多数内部算法和数据处理来说 Qt 发挥的作用较小 我经常会遇到从 std string 转换为 QString 的需要 反之亦然 我的倾向是尽可能使用 std str
  • Git 元数据 - 有没有办法添加独立于每个分支的 git 元数据?

    最终目标 我想要由 Git 跟踪的文件 但让这些文件成为所有分支的版本相同 如果您 gitignore 文件 这些文件对于所有分支都是相同的 但不幸的是不会被跟踪 当我跑步时git push或类似的 我需要这些文件在存储库等之间传递 例如
  • RubyMine 按路径搜索文件项目

    在 SublimeText 2 中我可以这样做 cmd t 然后输入文件名或文件夹名称 然后显示结果 是与我正在搜索的术语匹配的文件与我正在搜索的术语的子文件夹中的文件相匹配的文件 例如 如果我的目录结构如下所示 models users
  • Python:如何不等待线程完成才能继续? [复制]

    这个问题在这里已经有答案了 所以我有一些代码等待 X 发生 然后创建一个线程并处理电子邮件 我正在寻找一种方法 让代码继续等待 X 即使 processEmail 正在另一个线程中发生 但目前代码只是等待线程完成 然后再等待 X 再次发生
  • Blazor Web Assembly 应用程序 .Net Core 托管:发布运行时错误

    我使用 NET 5 0 RC1 Framework 创建了一个托管在 NET Core 应用程序内的简单 Blazor Web Assembly 项目 并在 Visual Studio 2019 预览版中的向导过程中添加了授权 它在调试中完