简体   繁体   English

当我尝试使用 ASP.NET 核心标识创建新用户时,为什么我的 ApiKey 变量位于 null 中?

[英]Why can it be that my ApiKey variable is in null when I try to create a new user using ASP.NET Core Identity?

I'm trying to use the ASP.NET Core Identity to manipulate the Account confirmation and password recovery in ASP.NET Core, I'm following step by step what the Microsoft docs about it says, but even so, I don't know why my ApiKey variable is null when it gets to Execute method in EmailSender class when I try to register a user?我正在尝试使用 ASP.NET 核心身份来操纵 ASP.NET 核心中的帐户确认和密码恢复,我正在逐步遵循 Microsoft 文档中关于它的内容,但即便如此,我也不知道为什么我的 ApiKey 变量当我尝试注册用户时,当它到达 EmailSender class 中的 Execute 方法时,是 null 吗?

Here is the Microsoft docs link what I'm using as guide:这是我用作指南的 Microsoft 文档链接:

https://docs.microsoft.com/en-us/aspnet/core/security/authentication/accconfirm?view=aspnetcore-3.0&tabs=visual-studio#register-confirm-email-and-reset-password https://docs.microsoft.com/en-us/aspnet/core/security/authentication/accconfirm?view=aspnetcore-3.0&tabs=visual-studio#register-confirm-email-and-reset-password

This is the content of my EmailSender class:这是我的 EmailSender class 的内容:

public class EmailSender : IEmailSender
    {
        public EmailSender(IOptions<AuthMessageSenderOptions> optionsAccessor)
        {
            Options = optionsAccessor.Value;
        }

        public AuthMessageSenderOptions Options { get; }

        public Task SendEmailAsync(string email, string subject, string message)
        {
            return Execute(Options.SendGridKey, subject, message, email);
        }

        public Task Execute(string apiKey, string subject, string message, string email)
        {
            var client = new SendGridClient(apiKey);
            var msg = new SendGridMessage()
            {
                From = new EmailAddress("Joe@contoso.com", "Joe El Salmón"),
                Subject = subject,
                PlainTextContent = message,
                HtmlContent = message
            };
            msg.AddTo(new EmailAddress(email));

            // Disable click tracking.
            // See https://sendgrid.com/docs/User_Guide/Settings/tracking.html
            msg.SetClickTracking(false, false);

            return client.SendEmailAsync(msg);
        }

I already configured my StartUp class.我已经配置了我的 StartUp class。 Next, I put the codelines I run not in CMD but in Package Administration Console, according to the Microsoft docs guide:接下来,根据 Microsoft 文档指南,我将运行的代码行不是在 CMD 中,而是在 Package 管理控制台中:

dotnet user-secrets init


dotnet new webapp -au Individual -uld -o WebPWrecover
cd WebPWrecover
dotnet run


dotnet user-secrets set SendGridUser SendMailAPIKey
dotnet user-secrets set SendGridKey <SendGridKey>

Also, in the route "C:\Users\User\AppData\Roaming\Microsoft\UserSecrets\" I see the JSON file with my User and Key.此外,在路径“C:\Users\User\AppData\Roaming\Microsoft\UserSecrets\”中,我看到了带有我的用户和密钥的 JSON 文件。

I really want to know what I'm doing wrong or if something is missing.我真的很想知道我做错了什么,或者是否缺少某些东西。 Thanks in advance.提前致谢。

Well, the solution here is to put the email to好吧,这里的解决方案是将 email 放到

return Execute(Options.SendGridKey, subject, message, email) 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用ASP.NET Core身份验证和基于令牌的身份验证时,为什么要登录新用户? - Why sign-in a new user when using ASP.NET Core Identity and token-based auth? 如何使用ASP.NET Core Identity v Preview 3.0创建自定义用户和角色? - How i can create custom user and role with ASP.NET Core identity v preview 3.0? ASP.NET 核心。 如何在没有身份用户帐户的情况下创建身份验证 cookie? - ASP.NET Core. How can i create an auth cookie without an identity user account? 为什么我不能用新播种的超级用户(Asp.Net Core Identity)登录? - Why can't I log in with the newly seeded power user (Asp.Net Core Identity)? User.Identity.Name 是 null 在我的 ASP.NET 核心 Web ZDB974238714CA8A14A7CE1D0 - User.Identity.Name is null in my ASP.NET Core Web API 我想为 ASP.NET 核心标识中的用户创建一个帐户,但我无法将数据插入表 dbo.AspNetUsers - I want to create an account for a user in ASP.NET Core identity but I can't insert the data into table dbo.AspNetUsers 在Asp.Net核心标识中创建没有UserManager的用户 - Create user without UserManager in Asp.Net Core Identity 当我尝试以天蓝色发布我的ASP.NET CORE Web应用程序时出现问题-无法加载文件或程序集&#39;Microsoft.Extensions.Identity.Core - Problem when i try to publish my ASP.NET CORE web app in azure - Could not load file or assembly 'Microsoft.Extensions.Identity.Core 如果我想使用ASP.NET MVC4创建ApiKey受限资源,我应该使用IAuthorizationFilter吗? - Should I be using an IAuthorizationFilter if I wish to create an ApiKey restricted resource with ASP.NET MVC4? 为什么运行 ASP.NET 6 项目时 `User.Identity.Name` `null`? - Why is `User.Identity.Name` `null` when running ASP.NET 6 project?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM