【问题标题】:System.ArgumentNullException when using TextEncodings使用 TextEncodings 时出现 System.ArgumentNullException
【发布时间】:2015-08-18 11:42:09
【问题描述】:

我的代码中有以下几行

    var issuer = "https://" + ConfigurationManager.AppSettings["auth0:DOMAIN"] + "/";

    var audience = ConfigurationManager.AppSettings["auth0:CLIENT_ID"];

    var secret = TextEncodings.Base64Url.Decode(
                  ConfigurationManager.AppSettings["Auth0:CLIENT_SECRET"]);

在最后一条语句中抛出了一个空异常。这是堆栈跟踪的一部分:

[ArgumentNullException: Value cannot be null.
Parameter name: text]

Microsoft.Owin.Security.DataHandler.Encoder.Base64UrlTextEncoder.Decode(String text) +99
AuthZero.API.Startup.ConfigureAuthZero(IAppBuilder app) in c:\Users\Abdi\Source\Repos\Auth0-Example\AuthZero.API\Startup.cs:34
AuthZero.API.Startup.Configuration(IAppBuilder app) in c:\Users\Abdi\Source\Repos\Auth0-Example\AuthZero.API\Startup.cs:21

显然 TextEncodings.Base64Url.Decode 正在寻找一个 String 参数,但我里面有另一个方法。不知道为什么它不起作用,因为我从另一个 github repo 复制。

这是我的 AppSettings,位于 Web.Config file:

   <appSettings>
     <add key="auth0:ClientId" value="gO0K9jkaxegRGRSHcZLuaiaCR3aSnDkH" />
     <add key="auth0:ClientSecret" value="1zvvKpyWGmFdufNldpB2A9xGuKV_YcAk-pxTNa9RnVTjTIhc5a8GVL6pcufM4owV" />
     <add key="auth0:Domain" value="amalexp.auth0.com" />
  </appSettings>

好的,我想我通过删除 ConfigurationManager.AppSettings 并直接插入字符串而不是查看 App.Config 文件解决了这个问题。但我收到“HTTP 错误 403.14 - 禁止访问” Web 服务器配置为不列出此目录的内容。”错误是另一回事。

【问题讨论】:

  • 调试程序以检查 ConfigurationManager.AppSettings["Auth0:1zvvKpyWGmFdufNldpB2A9xGuKV_YcAk-pxTNa9RnVTjTIhc5a8GVL6pcufM4owV"] 在运行时的计算结果。从它的声音来看,它是null
  • 你是对的,计算结果为 null,知道为什么吗?
  • 您的应用设置中似乎还没有该设置键。

标签: asp.net exception encoding auth0


【解决方案1】:

代码中的设置名称中有空格和下划线,但 app.config 中没有。

【讨论】:

  • 抱歉,我做了这些更改以隐藏键。我的实际文件中没有空格或下划线。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-07-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-04-03
  • 1970-01-01
相关资源
最近更新 更多