[英]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.