none
The type or namespace name 'Web' could not be found RRS feed

  • Question

  • So I am feeling a little snow blind with this.

    It seems like when I try to create an instance of Web it seems to error. I am following a tutorial here and so this is unexpected and I cannot for the life of me see where  I am going wrong or whats missing.

    // Create a Web transport for sending email.
                var transportWeb = new Web(credentials);
    using System;
    using System.Collections.Generic;
    using System.Data.Entity;
    using System.Linq;
    using System.Security.Claims;
    using System.Threading.Tasks;
    using System.Web;
    using System.Xml;
    using Microsoft.Web;
    using System.Net.Mime;
    using Microsoft.AspNet.Identity;
    using Microsoft.AspNet.Identity.EntityFramework;
    using Microsoft.AspNet.Identity.Owin;
    using Microsoft.Owin;
    using Microsoft.Owin.Security;
    using HecticHousehold.Models;
    using SendGrid;
    using System.Net;
    using System.Configuration;
    using System.Diagnostics;
    using SendGrid.Helpers.Mail;
    using System.Net.Mail;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    namespace HecticHousehold
    {
        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 EmailAddress("Joe@contoso.com", "Joe S.");
                myMessage.Subject = message.Subject;
                myMessage.PlainTextContent = message.Body;
                myMessage.HtmlContent = message.Body;
    
                var credentials = new NetworkCredential(
                           ConfigurationManager.AppSettings["mailAccount"],
                           ConfigurationManager.AppSettings["mailPassword"]
                           );
    
                // Create a Web transport for sending email.
                var transportWeb = new Web(credentials);


    Friday, January 19, 2018 10:05 PM

All replies

  • You should post the link for the tutorial for some context.

    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Friday, January 19, 2018 10:35 PM
    Moderator
  • https://docs.microsoft.com/en-us/aspnet/mvc/overview/security/create-an-aspnet-mvc-5-web-app-with-email-confirmation-and-password-reset
    Friday, January 19, 2018 11:02 PM
  • Hi Withington.UK,

    Please check the version of SendGrid, please right click your project -> managed Nuget Packages... -> Installed -> click SendGrid -> check the description.

    if you use V3 and latest version, please refer to the following code.

    private async Task configSendGridasync(IdentityMessage message)
            {
                //var myMessage = new SendGridMessage();
                //myMessage.AddTo(message.Destination);
                //myMessage.From = new EmailAddress("Joe@contoso.com", "Joe S.");
                //myMessage.Subject = message.Subject;
                //myMessage.PlainTextContent = message.Body;
                //myMessage.HtmlContent = message.Body;
    
                //var credentials = new NetworkCredential(
                //           ConfigurationManager.AppSettings["mailAccount"],
                //           ConfigurationManager.AppSettings["mailPassword"]
                //           );
    
                //// Create a Web transport for sending email.
                //var transportWeb = new Web(credentials);
    
    
                var apiKey = ConfigurationManager.AppSettings["NAME_OF_THE_ENVIRONMENT_VARIABLE_FOR_YOUR_SENDGRID_KEY"];//Environment.GetEnvironmentVariable("NAME_OF_THE_ENVIRONMENT_VARIABLE_FOR_YOUR_SENDGRID_KEY");
                var client = new SendGridClient(apiKey);
                var from = new EmailAddress("test@example.com", "Example User");
                var subject = message.Subject; 
                var to = new EmailAddress("test@example.com", "Example User");
                var plainTextContent = message.Body; 
                var htmlContent = message.Body;
                var msg = MailHelper.CreateSingleEmail(from, to, subject, plainTextContent, htmlContent);
                var response = await client.SendEmailAsync(msg);
    
                // Send the email.
                if (client != null)
                {
                    await client.SendEmailAsync(msg);
                }
                else
                {
                    Trace.TraceError("Failed to create Web transport.");
                    await Task.FromResult(0);
                }
            }

    https://sendgrid.com/docs/Integrate/Code_Examples/v3_Mail/csharp.html

    In addition, since it is a SendGrid issue, you could also post your issue sendgrid forum for suitable support.

    https://support.sendgrid.com/hc/en-us

    Note: This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you.
    Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there.
    There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.

    Best regards,

    Zhanglong


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, January 22, 2018 5:31 AM
    Moderator