user6272884
user6272884

Reputation: 101

mvc identity, sending email confirmation with extra parameter

I am developing a mvc app using email confirmation using this line

 await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

but I would like to send extra parameter in that method

 public virtual Task SendEmailAsync(TKey userId, string subject, string body);

is part of

 public class UserManager<TUser, TKey> : IDisposable

how can overwrite that or create an extension that accept another parameter.?

Upvotes: 0

Views: 341

Answers (2)

Ssheverdin
Ssheverdin

Reputation: 111

Usually in MVC using some other class that inherets from User<TUser, TKey> like "UserManager", but it should work in any situation.

so it would be something like:

public static class UserManagerExtension
{
            public static Task SendEmailAsync(this UserManager manager, 
        TKey userId, string subject, string body, string extraParameter)
            {
                        //Do something with parameter
                        return manager.SendEmailAsync(userId, subject, body);
            }
}

So if UserManager inherets from User<TUser, TKey>, just replace TKey type with yours(string by default) and it should work.

Upvotes: 0

hyankov
hyankov

Reputation: 4120

Simply - you don't. Instead, wrap the method inside your own method which receives the extra parameter and does whatever with it.

I assume you want to use the 'extra parameter' to form your email body or subject.

private void MyMethod(... whatever ...)
{
  // TODO: Use whatever
  await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking here");
}

Upvotes: 1

Related Questions