Sent by email at regular intervals for password recovery user

I have a table created by Identity as AspNetUser .

I want to send an email to the appropriate user if he has not updated his password within six months. I have to send mail after 60 days and after that every 3 days. I am using .net framework 4.5.2, asp.net, mvc 5, identity2
My model

  public class IdentityUser : IUser { public IdentityUser(); public IdentityUser(string userName); . . public DateTime LastUpdateDate{get;set;} } 

My controller

 public ActionResult PasswordSendMail() { my code for checking six month... } 

But mail should be sent once on the 60th day from LastUpdateDate and every three days.
If I put the code in the controller, the action should be called. I have to send without calling any controller specifically.
I want to send mail to users, regardless of whether the user is logged in or not. when the time reached by mail must be sent by the background process.
how to integrate windows service with the current project. A short answer will be helpful
thanks in advance

+5
source share
5 answers

Here you have two main options. The first and simplest is simply not to worry about notifying the user exactly after a certain period of time and just notifying them when you log in if it is time to change the password. You can simply add your code to check if the password was older than the set timeframe for your login code, and then redirect it to the password change form if this is the time. Or, if you really want to be interested in this, you can create an action filter that performs this check and redirects to the password change form, so the user will not be able to do anything until he has updated his password.

If you really want to send a scheduled email, you need something that can run the code on a scheduled basis. You have two options in this regard. First, you can create a console application containing this code, and then just use something like the Task Scheduler on Windows to run it according to the schedule. Secondly, you can use something like Revalee to invoke your scheduled action.

+5
source

If you want to plan actions on your server, I would recommend creating a Windows service using a timer that calls the URL at the moment. I tried the task scheduler, and for me it was not reliable enough.

This is the most important part of your Windows service.

 protected override void OnStart(string[] args) { LaunchTimer(MilliSecondsToNextLaunch()); } protected void LaunchTimer(double interval) { Timer = new Timer { Interval = interval }; Timer.Elapsed += OnTimer; Timer.Start(); } protected override void OnTimer(object sender, ElapsedEventArgs args) { using (var client = new WebClient()) { client.DownloadString(siteUrl); } SetIntervalForTimer(MilliSecondsToNextLaunch() + 1000); } protected void SetIntervalForTimer(double nextInterval) { Timer.Stop(); Timer.Interval = nextInterval; Timer.Start(); } 
+1
source

You can do this using the SQL stored procedure. Modify the Identity table by adding a new LastUpdateDate column.

In the stored procedure, check the date difference between the last update date and the current date, save the value in an integer variable, then use the IF-ELSE statement to check if the update value exceeds 6 months.

If true, select the email addresses of this user.

Now read these email addresses in ASP.Net and send an email to these users.

If you can send me a diagram of your Identity table, I can help you with the code.

For additional help feel free to contact.

0
source

We have already developed a solution for this requirement.

  • On asp.net or mvc website add web service as interface to send password

  • Develop a basic console program, add a link to the service you made in step 1, execute the api service to send an email

when using the Windows service:

  1. register the console program as a Windows service using NSSM
  2. add a scheduler task to start / stop the console program service in step # 3. http://forums.asp.net/t/1758972.aspx?start+and+stop+windows+service+using+windows+task+scheduler

But windows service, imo, is not needed. In our case, we simply use the Windows task scheduler to launch the console program, and the console program then calls the web service and an email is sent

0
source

Check this solution by solving the problem

  • Create a console application in Visual C #. Write your custom logic to verify your validation.

0
source

Source: https://habr.com/ru/post/1243579/


All Articles