我想在ASP.NET网站上每24小时执行一次代码 [英] I want to executing code after each 24 hours in ASP.NET webiste

查看:177
本文介绍了我想在ASP.NET网站上每24小时执行一次代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有网页的ac#功能即ASP.net那么我将如何以编程方式调用这个后端函数,让我们每天凌晨1点说。



例如我希望每晚12.00 pm发送邮件

我如何安排。




< b>我尝试了什么:



I have a c# function for web-page i.e ASP.net So how would i programmatically call this back-end function let say everyday at 1:00 am.

for example i want send mail every night in 12.00 pm
how can i schedule.


What I have tried:

private void SendHtmlFormattedEmail(string recepientEmail, string subject, string body)
    {
        using (MailMessage mailMessage = new MailMessage())
        {
            mailMessage.From = new MailAddress(ConfigurationManager.AppSettings["UserName"]);
            mailMessage.Subject = subject;
            mailMessage.Body = body;
            mailMessage.IsBodyHtml = true;
            mailMessage.To.Add(new MailAddress(recepientEmail));
            SmtpClient smtp = new SmtpClient();
            //smtp.EnableSsl = true;
            smtp.Host = ConfigurationManager.AppSettings["Host"];
            smtp.EnableSsl = Convert.ToBoolean(ConfigurationManager.AppSettings["EnableSsl"]);
            System.Net.NetworkCredential NetworkCred = new System.Net.NetworkCredential();
            NetworkCred.UserName = ConfigurationManager.AppSettings["UserName"];
            NetworkCred.Password = ConfigurationManager.AppSettings["Password"];
            smtp.UseDefaultCredentials = true;
            smtp.Credentials = NetworkCred;
            smtp.Port = int.Parse(ConfigurationManager.AppSettings["Port"]);
            smtp.Send(mailMessage);
        }
    }

推荐答案

取决于您的托管服务。

我使用Arvixe,他们提供了一个任务计划程序作为网站管理面板的一部分:如何在DotNetPanel中使用Schedule Task来执行URL Arvixe博客 [ ^ ]

您的主机可能会执行非常相似的操作,但确切的详细信息将取决于您的主机 - 所以从他们的文档或技术支持。

这不是一个不常见的要求 - 我将它用于定期备份 - 所以他们应该习惯它。
Depends on your hosting service.
I use Arvixe, and they provide a Task Scheduler as part of the website admin panel: How to Use Schedule Task in DotNetPanel to Execute a URL | Arvixe Blog[^]
It's likely that your host does something very similar, but the exact details will depend on your host - so start with either their documentation, or technical support.
This isn't an uncommon requirement - I use it for regular backups - so they should be pretty used to it.


写Windows服务。您无法在网页中使用此功能。
Write windows service. You cannot use this functionality in webpage.


这篇关于我想在ASP.NET网站上每24小时执行一次代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆