Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9259231
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:36:19+00:00 2026-06-18T12:36:19+00:00

I am building an MVC 4 application starting with the default internet application. My

  • 0

I am building an MVC 4 application starting with the default internet application. My goal is to send a confirmation email to users as they register to the website, i have managed to send the confirmation email but when i click on it the account is not being confirmed.

Note: I know the Register action is crowded, i will separate pieces to different files when i make it work.

*This is what i have done:*

Register Action

[HttpPost]
    [AllowAnonymous]
    [ValidateAntiForgeryToken]
    public ActionResult Register(RegisterModel model)
    {
        if (ModelState.IsValid)
        {
            try //CreateUserAndAccount
            {
                var token = WebSecurity.CreateUserAndAccount(model.UserName, model.Password, null, true);
                if (token != null)
                {
                    var hosturl =
                        System.Web.HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority) +
                        "/Account/ConfirmAccount?token=" + token;

                    var confirmationLink = string.Format("<a href=\"{0}\">Clink to confirm your registration</a>",
                                                         hosturl);




                    var message = new MailMessage("komengem@gmail.com", model.UserName)
                    {
                        Subject = "Please confirm your email",
                        Body = confirmationLink
                    };

                    var client = new SmtpClient();
                    client.EnableSsl = true;
                    client.Send(message);
                }

                TempData["message"] = string.Format(
                    "Thank you for registering. An email has been sent to {0}. " +
                    "Please check your email and use the enclosed link to finish registration.", model.UserName);
                return RedirectToAction("Index", "Home");
            }
            catch (MembershipCreateUserException e)
            {
                ModelState.AddModelError("", ErrorCodeToString(e.StatusCode));
            }
        }

ConfirmAcount Action

public ActionResult ConfirmAccount(string ID)
    {
        //return View("ConfirmAccount");
        var confirmationToken = Request["token"];
        if (!String.IsNullOrEmpty(confirmationToken))
        {
            var user = WebSecurity.CurrentUserName;
            WebSecurity.ConfirmAccount(confirmationToken);
            WebSecurity.Login(user, null);
            return View("Welcome");
        }

        TempData["message"] = string.Format(
                    "Your account was not confirmed, please try again or contact the website adminstrator.");
        return RedirectToAction("Index", "Home");            
    }

Also Tried

public ActionResult ConfirmAccount(string ID)
    {
        if (string.IsNullOrEmpty(ID) || (!Regex.IsMatch(ID,
                        @"[0-9a-f]{8}\-([0-9a-f]{4}\-){3}[0-9a-f]{12}")))
        {
            TempData["tempMessage"] =
                "The user account is not valid. Please try clicking the link in your email again.";
            return View();
        }
        MembershipUser user = Membership.GetUser(new Guid(ID));

        if (!user.IsApproved)
        {
            user.IsApproved = true;
            Membership.UpdateUser(user);
            FormsAuthentication.SetAuthCookie(user.UserName, false);
            return RedirectToAction("Login");
        }
        WebSecurity.Logout();
        TempData["tempMessage"] = "You have already confirmed your email address... please log in.";
        return RedirectToAction("Login");
    }      

Could anyone please show me how to make this work, or perhaps suggest a different way to make this work??

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T12:36:20+00:00Added an answer on June 18, 2026 at 12:36 pm

    I encourage you to use Postal, which is a simple to use email-creation package. It’s available as a nuget-package.

    Also take a look at Kevin Junghans blogpost on the subject! Email confirmation

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When building an ASP.NET MVC application with a goal of high availability, is it
I'm building an asp.net MVC application where users can attach a picture to their
I'm building an asp.net mvc application. In my application I have a dashboard that
I have an ASP.NET MVC application I'm building and I'm using a Master page.
I am building an asp.net mvc application. I have my top menu structure which
We have an existing MVC application that we're building using TeamCity and things were
I have been building ASP.NET MVC application and I'm worried about potential multi-threading issues
We have started building an asp.net mvc application. Application will consist with one main
I'm building an asp.net mvc application for users to enter an essay contest. I
I'm building ASP.Net MVC application kinda Game which deal a lot with online users

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.