问题
I have a windows shared hosting and i need to run some scheduled c# executable every day for create sitemap, send newsletter,etc...
The provider tell me that i can't run executable for security reason. Whay can i do?
The provider suggest me to buy a VPS, but do not think it makes sense to spend more money just to run some scheduled task.
Does exists an alternative way?
回答1:
Implement your once-a-day task in an asp.net page on your shared server. Then set-up a process, on a machine that you do have full access to, to request that page once a day at a scheduled time.
If the once-a-day processing is time-consuming then you could do it in a thread created by the page. This would stop the request timing-out.
To prevent abuse you could give the page an obscure name, limit access via ip address (if the shared server's control panel allows that), and/or require authentication by the requesting process. The page could also store the last request time in cache and only do the required processing if sufficient time had elapsed since it was last requested.
回答2:
Jeff Atwood has created blog entry on this.
In short:
- Add an item to the cache
- Make it expire on your wanted interval
- Add a trigger to execute when the cache expires
- Re-add your item in the trigger
I would first consider the solution from Andy, it looks easier to manage.
回答3:
You can use ATrigger scheduling service on shared hosting simply. A .Net library is also available to create scheduled tasks without overhead. Also you have reporting panel to list tasks and log all possible errors.
Disclaimer: I was among the ATrigger team. It's a freeware and I have not any commercial purpose.
回答4:
It's not ideal, but you could inherit all your pages from a basepage (a page which inherits System.Web.UI.Page and subsequent pages inherit from that), and on each page load (in the basepage) you could check a database table of tasks which are to run on certain timeframes. If, on a given page load, the task which is to be run is selected at a given time, and that matches (or is past the time) the page was requested you could run it at that time.
This unfortunately depends on a website user visiting your site at or near the time you wish the job to run. Also, another drawback would be that if the user who requested the page may be waiting if your job is running synchronously to the execution of the remainder of the page.
Hope this helps.
回答5:
There are schedule tasks in shared hosting panel. http://pasteboard.co/2oBUrVeM.png
You may trigger the url of your action method that sends the emails.
来源:https://stackoverflow.com/questions/5245612/windows-shared-hosting-custom-scheduled-task