locked
Tutorial Help - Add email confirmation and password reset RRS feed

  • Question

  • User-1314346660 posted

    Hello Experts,

    I want to add user email confirmation and password reset functionality to my web applications. At the moment this is done manually by the administrator. Can someone please point me to an online tutorial or some notes on how to do this?

    I am using ASP.net Webforms applications with the built in Microsoft Individual User Accounts authentication. I have set up a SendGrid account for the purpose. I have read the Microsoft guidance here:

    https://docs.microsoft.com/en-us/aspnet/mvc/overview/security/create-an-aspnet-mvc-5-web-app-with-email-confirmation-and-password-reset

    But this is for MVC and it doesn't fully translate to web forms. I am very grateful in advance for your help.

    Billson3000

    Wednesday, January 9, 2019 11:07 AM

Answers

All replies

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, January 9, 2019 1:02 PM
  • User-1314346660 posted

    Thank you mge.

    I have followed the tutorial. Seems like there is an error in their somewhere. On the identityconfig.cs it create 2 errors:

    CS0246 C# The type or namespace name could not be found (are you missing a using directive or an assembly reference?) on both:

    var myMessage = new SendGridMessage();

    and 

    var transportWeb = new Web(credentials);

    Here is my full code. Any idea what I might be doing wrong?

    using System;
    using System.Security.Claims;
    using System.Threading.Tasks;
    using Microsoft.AspNet.Identity;
    using Microsoft.AspNet.Identity.EntityFramework;
    using Microsoft.AspNet.Identity.Owin;
    using Microsoft.Owin;
    using Microsoft.Owin.Security;
    using SendGrid;
    using System.Net;
    using System.Configuration;
    using System.Diagnostics;
    using Email.Models;
    
    namespace Email
    {
        public class EmailService : IIdentityMessageService
        {
            public async Task SendAsync(IdentityMessage message)
            {
                await configSendGridasync(message);
            }
    
            // Use NuGet to install SendGrid (Basic C# client lib) 
            private async Task configSendGridasync(IdentityMessage message)
            {
                var myMessage = new SendGridMessage();
                myMessage.AddTo(message.Destination);
                myMessage.From = new System.Net.Mail.MailAddress("Royce@contoso.com", "Royce Sellars (Contoso Admin)");
                myMessage.Subject = message.Subject;
                myMessage.Text = message.Body;
                myMessage.Html = message.Body;
    
                var credentials = new NetworkCredential(
                           ConfigurationManager.AppSettings["emailServiceUserName"],
                           ConfigurationManager.AppSettings["emailServicePassword"]
                           );
    
                // Create a Web transport for sending email.
                var transportWeb = new Web(credentials);
    
                // Send the email.
                if (transportWeb != null)
                {
                    await transportWeb.DeliverAsync(myMessage);
                }
                else
                {
                    Trace.TraceError("Failed to create Web transport.");
                    await Task.FromResult(0);
                }
            }
    
        }

    Thursday, January 10, 2019 9:02 AM
  • User-1314346660 posted

    I have it now.

    The references in this document to the SendGrid scripts are out of date. If anyone else finds this thread then you will need to refer to the SendGrid documentation to ensure that the mail sender is configured correctly.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, January 10, 2019 4:58 PM