IIS 日志失败:Microsoft.AspNetCore.Server.Kestrel[13] JwtBearerOptions

2024-03-12

在 IIS 中运行已发布的 API 时,出现以下错误:

Hosting environment: Production
Content root path: C:\inetpub\My_API
Now listening on: http://127.0.0.1:44674
Application started. Press Ctrl+C to shut down.
fail: Microsoft.AspNetCore.Server.Kestrel[13]
      Connection id "0HM9MTIMQIFTF", Request id "0HM9MTIMQIFTF:00000001": An unhandled exception was thrown by the application.
System.ArgumentNullException: String reference not set to an instance of a String.
Parameter name: s
   at System.Text.Encoding.GetBytes(String s)
   at My_API.Startup.<ConfigureServices>b__4_2(JwtBearerOptions options) in D:\repos\API\My_API\Startup.cs:line 173
   at Microsoft.Extensions.Options.ConfigureNamedOptions`1.Configure(String name, TOptions options)
   at Microsoft.Extensions.Options.OptionsFactory`1.Create(String name)
   at Microsoft.Extensions.Options.OptionsMonitor`1.<>c__DisplayClass10_0.<Get>b__0()
   at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
   at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
   at System.Lazy`1.CreateValue()
   at Microsoft.Extensions.Options.OptionsCache`1.GetOrAdd(String name, Func`1 createOptions)
   at Microsoft.Extensions.Options.OptionsMonitor`1.Get(String name)
   at Microsoft.AspNetCore.Authentication.AuthenticationHandler`1.InitializeAsync(AuthenticationScheme scheme, HttpContext context)
   at Microsoft.AspNetCore.Authentication.AuthenticationHandlerProvider.GetHandlerAsync(HttpContext context, String authenticationScheme)
   at Microsoft.AspNetCore.Authentication.AuthenticationService.AuthenticateAsync(HttpContext context, String scheme)
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context)
   at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext)
   at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
   at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Server.IISIntegration.IISMiddleware.Invoke(HttpContext httpContext)
   at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication`1 application)
Application is shutting down...

在Startup.cs文件中,生成错误的行的代码如下:

services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJwtBearer(options => 
options.TokenValidationParameters = new TokenValidationParameters
      {
          ValidateIssuer = false,
          ValidateAudience = false,
          //ValidateLifetime = false,
          ValidateIssuerSigningKey = true,
          //ValidIssuer = "https://locahost",
          //ValidAudience = "https://localhost",
          IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["Key_Token"])),
                ClockSkew = TimeSpan.Zero
      });

在开发模式下执行 API 不会出现任何问题,身份验证也没有问题,但在生产模式下执行 API 时,服务器响应状态为 500。

如果有人可以帮我看看问题所在。

感谢一切。

一切顺利。


我已经找到了解决我的问题的方法。 发生错误的原因是在 Startup.cs 中找不到生成 JWT 令牌的密钥。在开发环境中,密钥存储在项目环境变量中,在应用程序LaunchSettings.json文件,但是当传递到生产环境时,在应用程序设置.json文件,所以在启动.cs当没有找到它时,它给出了错误。 为了解决这个问题,我将创建的变量保存在应用程序LaunchSettings.json文件输入应用程序设置.json文件,现在一切正常。

Thanks.

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

IIS 日志失败:Microsoft.AspNetCore.Server.Kestrel[13] JwtBearerOptions 的相关文章

  • .NET 的 BLOB 分布式存储?

    我正在寻找一个经过相当好的测试的库 服务器来存储持久的分布式哈希表 我对使用基于 SQL 的解决方案犹豫不决 因为数据是高度面向文档的 由数百万个约 64KB 的 blob 组成 只有一个索引 由所述 BLOB 的哈希计算 并且需要能够进行
  • 插入后,数据库中仅插入“字符串”的一个字符

    Below is my table screenshot Data after insertion C 代码 SqlConnection con new SqlConnection connectionsession Con con Ope
  • 颜色变换器功能上的堆栈溢出错误

    我有两种颜色 红色 和 鲑鱼色 我需要动态创建面板以及面板背景颜色 这些颜色必须介于两种颜色之间 红色 public Color x y protected void Page Load object sender EventArgs e
  • 异步提交或回滚事务范围

    正如许多人所知 TransactionScope当async await Net 中引入了模式 如果我们尝试使用一些它们就会损坏await在事务范围内调用 现在这个问题已经解决了 感谢范围构造函数选项 a 17527759 1178314
  • 如果将其名称作为参数传递,如何在方法中打开表单

    我正在尝试创建一个标准方法来根据传递给它的参数打开表单 基本上 要完成此任务 using Quotes newQte new Quotes newQte ShowDialog 通过替换 Quotes with a passed parame
  • .NET 是否有相当于 Python 中的 **kwargs 的功能?

    我一直无法通过典型渠道找到这个问题的答案 在Python中我可以有以下函数定义 def do the needful kwargs Kwargs is now a dictionary i e do the needful spam 42
  • 寻找自定义 SynchronizationContext 的示例(单元测试所需)

    我需要定制同步上下文 http msdn microsoft com en us library system threading synchronizationcontext aspx that 拥有一个运行 Posts 和 Sends
  • VSTS部署IIS应用程序winrm并更改appsettings.json

    我正在使用 部署 IIS 应用程序 winrm 任务在另一台计算机上部署 IIS 应用程序 此任务部署 zip 文件 在此 zip 中有一个 appsettings json 其变量以下划线开头和结尾 我需要替换每个环境的 appsetti
  • 检查对象是否更改的最佳实践是什么?

    我需要知道如何检查对象是否发生更改 基本上我需要一个名为 TrackChanges 的属性 当我将其设置为 true 一次并且如果该对象中的任何数据被 更改 时 同一对象上的方法 IsObjectChanged 可以返回 true 您是否曾
  • sitecore 站点内嵌套虚拟目录或应用程序是否可能

    我想将 ASP NET Web 应用程序嵌套在 sitecore 站点中 如下所示
  • 找不到 OAuth2 参数

    我正在尝试使用 OAuth 2 0 来授权 google docs API 根据谷歌给出的例子https developers google com google apps documents list authorizing reques
  • 使用编译时编织进行依赖注入? [关闭]

    Closed 这个问题不符合堆栈溢出指南 help closed questions 目前不接受答案 我只是想了解 PostSharp 老实说我认为它太棒了 但有一件事对我来说很难如何纯依赖注入 不是服务定位器 无法完成 https cod
  • 在c#中创建sql连接

    我是这个网站的新手 也是编程的新手 我目前正在通过销售点创建库存系统 它使用模态和非模态形式 我的问题是 我正在研究change password对话框必须连接到数据库才能覆盖密码字段 我使用的数据库是Microsoft SQL Serve
  • 如何从 SOAP 响应中删除额外的结果标签

    我知道这个问题以前曾被问过 但我在任何地方都找不到答案 问题是我的 asmx 文件中有以下代码 namespace IrancellSmsServer SoapDocumentService RoutingStyle SoapService
  • 如何以一种形式发布两个或多个模型?

    我正在为一个项目开发互联网课程计划应用程序 该课程计划是根据以下模型构建的 使用数据库优先方法中的实体框架生成 public partial class Subject public int Id get set public string
  • VS2017在nuget包中将“Build Action”设置为“Content”

    我创建我的nuget包在gitlab使用以下命令行 nuget pack Prop Configuration Release OutputDirectory nuget REPONAME APPNAME APPNAME csproj 如果
  • 在我的网站上显示 Google Analytics(分析)仪表板

    我设置了一个 ASP NET 网站 并使用 Google Analytics 进行页面跟踪 我唯一不喜欢的是我必须离开我的网站 到 Google Analytics 网站 才能看到该报告 有什么方法可以使用他们拥有的所有 AJAX 在我自己
  • ELMAH 将其数据保存在哪里?

    我刚刚安装了 ELMAH MVC 更多信息here http nuget org packages Elmah MVC 并且想知道其数据保存在哪里 我读到您可以选择设置数据库进行存储 但似乎默认安装使用 内存中 它是如何工作的 如果我回收应
  • Microsoft Teams 中私人消息的传入 Webhook

    我可以从 C 应用程序或 PS 脚本创建传入 Webhook 将 JSON 消息发送到 MSFT 文档所解释的通道 但是 我想使用传入的 webhook 将 JSON 消息从我的应用程序发送到用户 作为私人消息 就像 Slack 允许的那样
  • 抽象类或接口。哪种方式是正确的?

    有两种方法可以选择抽象类或接口 微软解决方案和Oracle解决方案 微软 设计指南 请使用抽象 在 Visual Basic 中为 MustInherit 类而不是接口来将协定与实现分离 http msdn microsoft com en

随机推荐