-
Notifications
You must be signed in to change notification settings - Fork 25.1k
Description
Description
Problem
Users following the "Account confirmation and password recovery in ASP.NET Core" tutorial are experiencing an error: "<AuthMessageSenderOptions> throws error as undefined" when implementing email functionality.
Root Cause
The current documentation shows this code for registering the options:
builder.Services.Configure<AuthMessageSenderOptions>(builder.Configuration);This doesn't properly bind to any specific configuration section, causing the AuthMessageSenderOptions class to be undefined when injected into services.
Proposed Solution
Update the "Configure app to support email" section in the tutorial to properly register the AuthMessageSenderOptions class:
// Add EmailSender as a transient service
builder.Services.AddTransient<IEmailSender, EmailSender>();
// Register the AuthMessageSenderOptions configuration instance
builder.Services.Configure<AuthMessageSenderOptions>(options =>
{
// Bind directly to the user secrets key
options.SendGridKey = builder.Configuration["SendGridKey"];
});The key change here is in how the AuthMessageSenderOptions class gets registered.
Instead of using builder.Services.Configure<AuthMessageSenderOptions>(builder.Configuration),
which doesn't properly bind to any specific configuration section, this update explicitly binds
the SendGridKey from the configuration to the options object.
This prevents the "<AuthMessageSenderOptions> throws error as undefined" error that can occur
when the options class isn't properly registered in the dependency injection container.
Page URL
Content source URL
https://github.com/dotnet/AspNetCore.Docs/blob/main/aspnetcore/security/authentication/accconfirm.md
Document ID
98e7aacb-2a01-d581-9b03-bfef2893163e
Platform Id
8efad4e0-06aa-bbe0-6133-4092aed18e42
Article author
Metadata
- ID: fe1bea60-d173-f6d2-3559-b147699e295a
- PlatformId: 8efad4e0-06aa-bbe0-6133-4092aed18e42
- Service: aspnet-core
- Sub-service: security