ASP.NET(C#) 定时执行一段代码
在Global.asax启动一条线程就ok了,下面是启动线程定时写文件的例子
Global.asax
C# code
Code
1<%@ Application Language="C#" %>
2<%@ Import Namespace="System.IO" %>
3<%@ Import Namespace="System.Threading" %>
4<script runat="server">
5 string LogPath;
6 Thread thread;
7 void WriteLog()
8 {
9 while (true)
10 {
11 StreamWriter sw = new StreamWriter(LogPath, true, Encoding.UTF8);
12 sw.WriteLine(thread.Name + ":" + DateTime.Now.ToString());
13 sw.Close();
14 Thread.CurrentThread.Join(1000 * 60);//阻止1分钟
15 }
16 }
17 void Application_Start(object sender, EventArgs e)
18 {
19 LogPath = HttpContext.Current.Server.MapPath("log.txt");
20 //在应用程序启动时运行的代码
21 thread = new Thread(new ThreadStart(WriteLog));
22 thread.Name = "写登录日志线程";
23 thread.Start();
24 }
25
26 void Application_End(object sender, EventArgs e)
27 {
28 //在应用程序关闭时运行的代码
29
30 }
31
32 void Application_Error(object sender, EventArgs e)
相关文档:
在Web编程过程中,存在着很多安全隐患。比如在以前的ASP版本中,Cookie为访问者和编程者都提供了方便,并没有提供加密的功能。打开IE浏览器,选择“工具”菜单里的“Internet选项”,然后在弹出的对话框里单击“设置”按钮,选择“查看文件”按钮,在弹出的窗口中,就会显示硬盘里 ......
<input id = " loFile " type = " file " runat = " server " >
<form method = " post " enctype =" multipart/form-data " runat = " server ">
</form >
1.获得上传文件的名称:(关键是PostedFile类的应用)
使用Path类中的GetFileName方法,具体如下:
lstrFileName = loFile.PostedFile.FileName ......
首先在 Web.Config 中添加模拟帐号
<identity impersonate="true" userName="administrator"password="password" />
其次 要添加 EXCEL com 组件。如果是EXCEL2003,则添加 EXcel library 11.0 ......
最近发现语音验证码越来越流行,比如有次在注册gmail邮箱看到过,还有msn页面也有语音验证码,还有国外一些网站等。
花时间研究了下,语音验证码主要跟一般验证码的区别就在于如何让验证码播放。本文语音验证码原理:从服务器生成验证码,
并保存到cookie中(getcode.aspx.cs),当点收听验证码的时候,调用javascirpt操作 ......
ASP.NET创设Web服务治理Web服务状态
2009-四-21
XML Web服务在种兑现衍生于WebService种的XML Web服务时,可以运用和其余ASP.NET应用程序雷同的状态治理选项。WebService种包孕好多公共ASP.NET对象,包括Session和Application对象。
Application对象提供一个存储运作在Web应用程序中的代码可访问的数据的机制,而S ......