簡體   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?

我正在嘗試使用 ASP.NET 核心身份來操縱 ASP.NET 核心中的帳戶確認和密碼恢復,我正在逐步遵循 Microsoft 文檔中關於它的內容,但即便如此,我也不知道為什么我的 ApiKey 變量當我嘗試注冊用戶時,當它到達 EmailSender class 中的 Execute 方法時,是 null 嗎?

這是我用作指南的 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

這是我的 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);
        }

我已經配置了我的 StartUp class。 接下來,根據 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>

此外,在路徑“C:\Users\User\AppData\Roaming\Microsoft\UserSecrets\”中,我看到了帶有我的用戶和密鑰的 JSON 文件。

我真的很想知道我做錯了什么,或者是否缺少某些東西。 提前致謝。

好吧,這里的解決方案是將 email 放到

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM