locked
Coding ASP.NET 4.5 Template to Use Email Confirmation and Passwird Reset features. RRS feed

  • Question

  • User1359246716 posted

    Thanks for reading.  My usual preamble...  I am trying to develop a web application using asp.net 4.5.  I'm running into problems because I am not familiar with the technology and much of the terminology and such.  I have been programming ASP.NET for a total of about 2 months.

    My Development Environment:   Windows 7 Home Premium - SP1;  Microsoft .Net Framework Version 4.6.00081;   MS Visual Studio Community 2015;  SQL Server Database;  C#;  NuGet [Microsoft.AspNet.Identity.EntityFramework], [Microsoft.Owin.Host.SystemWeb], [Microsoft.AspNet.Identity,Owin], [Microsoft.Owin], [Microsoft,Owin.Security.OAuth], [Microsoft,Owin.Security], [Microsoft,Owin.Security.Cookies], [Microsoft.AspNet.Identity.Core], [Microsoft.AspNet.Web.Optimation], [Microsoft,Owin.Security.Google], [Microsoft,Owin.Security.Facebook], [Microsoft,Owin.Security.MicrosoftAccount], [Microsoft,Owin.Security.Twitter]...  (<-- These packages are all installed along with others)

    My Caveats:  I am trying to develop everything locally - without using Azure or any cloud services.  Just my local servers.  Because I need a mail server in order to send out the user password confirmations, I have installed hMailServer on my development machine.

    The Meat of my problem...   I have been developing pages - that is going along well.  But when my app project was first created, the templates created the Registration and Login pages, but the email confirmation and password reset pages (although I can see them) are not invoked (configured for use).  I find links within the web.config file that reference how to complete the set up of the confirmation and reset, but they all refer to using Azure and SendGrid (which I do not have installed), there seems to be no other general documentation for how to use a service such as the hMailServer mail server I have installed.  Yes, I have searched the hmailserver forum for how to integrate it with asp.net 4.5, but I am not seeing what I am looking for.   I would be happy to replace hMail with any other mail server, but again, I am looking for something on my own server that I can fully control.

    Can anyone here point to a website, video, or book that provides step-by-step detailed instruction as to how to get the confirmation and reset pages to configure?  In addition to what I can find (sendgrid and azure specific), the problem I have is that documentation is very general and apparently written for people who have a lot of experience with ASP, C# and windows development. For example, they will say, enter this code... but not say where (in what files), or how that code is called or accessed, etc... another problem I have with much of the documentation is that it is not for version 4.5 and therefore the code, pages, and other objects it references is not germane to the template I am using.

    So, again, if anyone have a link for absolute beginners that can explain how to get the mail based confirmation and password rest pages coded, I would appreciate the help. 

    Please stay tuned... I think I have figured this out....  Will test and report back.

    Wednesday, December 2, 2015 7:37 PM

Answers

All replies

  • User1124521738 posted

    I ignored the bit about sendgrid when I started using the reset process and the auto generated boilerplate code and just used the plain smtp client and did my own orchestration of the reset email and using the auth framework for the token.  I'm only doing the reset and not confirmation as this is for an administration control panel rather than a general user self-registration application.  if using plain ol' smpt client you can use the system.net web.config (see https://github.com/ninianne98/CarrotCakeCMS-MVC/blob/master/CMSAdmin/Web.config) entry to generate eml files on your local disk and not need to run a local smtp (SmarterMail lite is my suggestion if you need an easy local free mail server).

    see https://github.com/ninianne98/CarrotCakeCMS-MVC/blob/master/CMSCore/Security/SecurityData.cs

    Start from ResetPassword(string Email) - generates the email and sends it - and ResetPassword(ApplicationUser user, string code, string password)  - verifies the token and does the reset - and work your way down/up with find references.  I'm using an embedded resource for the reset email message body template but you could substitute any number of methods for getting the email body into the system (local file, database, hard coded string etc.)

    Wednesday, December 2, 2015 7:57 PM
  • User614698185 posted

    Hi Blktoptrvl,

    if anyone have a link for absolute beginners that can explain how to get the mail based confirmation and password rest pages coded

    Here are some tutorials about Account Confirmation and Password Recovery with ASP.NET Identity:

    Account Confirmation and Password Recovery with ASP.NET Identity

    Create a secure ASP.NET MVC 5 web app with log in, email confirmation and password reset

    Best Regards,

    Candice Zhou

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, December 3, 2015 7:13 AM
  • User1359246716 posted

    Thanks Candice, I will take a look at your suggested link...

    ...in the meantime, I want to add more information to this thread as I learn what I need to do.  This information may (or may not) turn out to be helpful to someone else who comes along and needs help.

    I have installed and configured a mail server to be able to send out emails.

    As per this documentation (setup instructions), http://www.asp.net/mvc/overview/security/create-an-aspnet-mvc-5-web-app-with-email-confirmation-and-password-reset I am now up to the step where I need to add code to the account controller.  Reading the page, at first glance, I see nothing that indicates what an account controller is, where it is located, or how to access/modify it. 

    Searching around, I right click the project (not the solution) and then click "Add" --> "New Item" --> and find the following items...  "Web API Controller Class(v2.1):, "Web Form User Control" and "AngularJs Controller".  I guess and choose the Web API Controller Class" which turns out NOT to look anything like what the instructions list, but...

    I search the net again and find www.w3schools.com/aspnet.mvc_controllers.asp and learn that an account controller is coded in the same file as the Web API Controller (because MS merged the two types of controllers).  Based on this article, I surmise that the controller file mentioned in the setup instructions does not exist in the project at this point. 

    Later in the setup document, I find that instead of just referencing the "controller," the author, now mentions the Controllers/AccountController.cs file.   It would have been helpful if this was mentioned above.  This is just another example to me of the poorly written MS documentation.

    Thursday, December 3, 2015 3:59 PM
  • User614698185 posted

    Hi Blktoptrvl,

    If you want to learn account controller, you could refer to this article:

    http://weblogs.asp.net/scottgu/asp-net-mvc-preview-4-release-part-1

    He basically says that the Account Controller from the MVC sample uses the ASP.NET membership provider, so you can use any of those. If you do not want to implement/use one of those, modifying the application to use your own user management would probably be the best option.

    Best Regards,

    Candice Zhou

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, December 8, 2015 8:35 AM