I'm looking for a scheduler for asp.net mvc. For example I want to send notification email weekly and also check expired date of the contract. Please suggest me solution in asp.net mvc.
Thanks in advance.
You may checkout Quartz.NET.
For scheduling functions, you might be better off using a Windows Service or a console app which is kicked-off by a scheduled task, rather than a web app. Web applications work best by responding to immediate inputs, and are not usually suited for handling actions that must start on their own. If you try to run a scheduling service as a background thread in a web app, you may run into problems when the app pool is recycled, or if IIS decides to kill your thread.
In any case, like Darin said, Quartz.NET is a good open source scheduling framework.
Have a look at my answer to the same question:
Scheduler for ASP.NET?
For the non-critical scheduled tasks you can definitely use Quartz.NET from your ASP.NET MVC project but you need to be sure to keep application alive most of the time what is not the case for the low traffic websites.
To keep application alive you can use http://www.uptimerobot.com/ which will ping your app every 5 minutes and also you will get site monitoring with it.
Look at the blog post for the simple example.
http://asmiki.wordpress.com/2011/05/25/using-quartz-net-enterprise-scheduler-to-schedule-jobs-in-asp-net-mvc-application/
Related
In my job we are building Web Apps that rely on a common Enterprise class. This class has a method that sends a request to our server every time the app_start or app_end event triggers so we can monitor the status remotely. But we are now requiring that at least once a day the web app reports its status, a bit like telemetry. I don't know how to accomplish this, so far I have found some options, but some have limitations:
Use hangfire. I don't like this since it requires to setup a Database or add more tables and install a new Nuget package on each project, but could be my last option.
Use a Windows Service that reads databases. This could be less work but it can't access the Web App web.config code
Use a Javascript tasks that sends an AJAX request. This requires to have an open web browser and is a big risk.
I'm looking for a server side approach that could allow to set to trigger an event or function at 1am.
I would got with Hangifire.
It is dead easy to setup and very reliable.
You don't need to setup the database, you might want to check memory storage:
https://github.com/perrich/Hangfire.MemoryStorage
Also check:
What is the equivalent to CRON jobs in ASP.NET? - C#
You can use FluentScheduler instead of Hangfire (it is more lightweight).
Instead of a Javascript task that sends an AJAX request you can use a WebJob or an Azure Function.
I have an MVC web app that uses a jquery web request to generate the users notifications in a perceived async way. The notifications are built on request by each user on the site.
However I have been asked to make the notifications readily available as the happen.
This I would traditionally do using a windows service that called the same web method over http. I was thinking that this might be a good candidate functionality for using node.js
Is the any example code to call a http method in a loop and would that scale well ?
found this package and seems to do what i needed
https://npmjs.org/package/node-cron-jobs
I also came across "forever" to run node as a child process that can be re-spawned if there are errors
If you're already running on ASP.NET MVC take a look at SignalR. This was written by Microsoft, is supported by them and provides functionality similar to the Socket.IO, node.js stack.
In dev environment I am using the ASP.NET configuration tool in Visual Studio to create a few users for testing. As I movel closer to QA and Production, I'm wondering what is the best way for me to automate the creation of a large amount (1000's) of users after application deployment.
I have a csv with all the usernames and passwords, roles etc. and I wan't to avail of the encryption and password salting security that is built in. I do not want to manually "Register" all these users.
I'm just not sure if this is something I can do (or instruct a db admin to perform for me).
Does anyone know of a way to achieve this?
Any assistance would be greatly appreciated.
Regards
The simplest solution would be to set up a "CSV Upload" form. The CSV would be processed by an MVC action calling Membership.CreateUser in a loop.
Probably, the performance of this will be good enough.
There's a few ways that I know of approaching a batch processing problem on an ASP.NET site.
Because of the wonky way an ASP.NET site's application pool can get recycled, batch processing is usually done on an external process.
Windows service
One way is a separate windows service, which gets the new excel and pumps that data in, and has a timer which keeps going around. I've seen this used often, and it is quite a pain, because it takes extra work to make it easily deployable.
Update ASP.Net membership from windows service
CacheItem
Second way is to use CacheItems and their expiration timers to do batch processing, what you do is you define a cache object with a long timer, and when that expires and the Removed-callback gets called, you do your database work. This is good because it deploys with your ASP.NET site, and you have your code in one logical place.
https://blog.stackoverflow.com/2008/07/easy-background-tasks-in-aspnet/
Workflow Foundation
Third way, is to make a workflow foundation service. That service gets a call from your ASP.NET site, which instantiates a WF service, that does some db work with your excel file, and then it goes into a while-loop with a delay of a month in it. This is good, because it is not tied to the lifespan of your ASP.NET application pool - you get more control, and this logic can be separated into a different IIS hosted WCF service.
http://msdn.microsoft.com/en-us/library/dd489452.aspx
Integrating with data is always a pain though, remember that the solution that gives you the least work and least chance of failure when deploying is the best solution.
I have an ASP.NET MVC web application which is hosted by an external provider, on IIS 7.
I wish to run a process every 15 minutes or so, which checks a backlog of emails that need to be sent, and actually sends them.
It seems that the normal way to do this is with Microsoft Message Queue, but since this is a hosted environment which I can't directly control, I won't be able to install or configure MSMQ.
So far I've decided to do it by appending rows to a table in my SQL Server database (same hosting).
So how should I implement the bit where I check the backlog and send the emails?
Should it be some kind of separate thread in my main web application, which restarts itself every 15 minutes?
Another option I considered was just opening an HTTP-POST interface which, when called with an appropriate admin password, runs an iteration of the email sender.
I could then create a small console app on my local PC which calls the interface every 15 minutes.
The first option is simpler, but the second might be more robust.
Any ideas?
I would recommend you taking a look at Quartz.NET. Also an important thing you should be aware is that the web server could unload the ASP.NET application from memory if it is not used meaning that all threads that have been spawned would simply die. That's one of the reasons why such tasks shouldn't be performed in ASP.NET applications but rather offloaded in Windows Services.
Jeff Atwood did a post on how he originally achieved the badge system on Stack Overflow using an expiring cache to reset the process periodically.
https://blog.stackoverflow.com/2008/07/easy-background-tasks-in-aspnet/
I have done something similar to this in the past sending emails out every day. The service was non essential, and it didn't matter if the emails missed a day or two, as they would go out eventually anyway, but the system worked quite well. It's all asp.net so works fine in the hosting environments I use, without access to service on the server or creating a local trigger from your desktop.
I'm working on a asp.net mvc project that will use MS Windows Workflow Foundation to manage client business work flows. These are long running workflows spanning in time over a year or two. So we've decided to use State Machine workflows. A workflow instance will be persisted to a database when not being used (or in idle).
I'm fairly new to MS WF and would like to find out the best practices for implementing the workflows for an asp.net mvc application.
More specifically, where should I host the WF runtime? In asp.net mvc or in a separate process like Windows Service?
I would be most grateful to hear success stories of how MS WF is implemented in asp.net mvc?
Any comments and ideas are welcome,
Thank you all,
Cullen
Are you referring to WF3 or WF4 which is a completely different piece of code.
With WF3 there is the central WorkflowRuntime and that is usually hosted somewhere at the application or possibly session level.
Updated
Some of the things to watch out for:
IIS can recycle the AppDomain at any time it wants to when there are no incoming calls being processed. An async workflow is NOT considered part of the request as it is running on another thread.
To migrate workflows from the old to the new AppDomain you need a persistence service.
The new AppDomain might not be activated right away causing delay activities not to execute as soon as you would expect.
Its is generally best to use the manual workflow scheduler but that makes writing code somewhat more complex as you have to schedule the work and then start execution.