62,046
社区成员
发帖
与我相关
我的任务
分享
<%@ Application Language="C#" %>
<%@ Import Namespace="System.IO" %>
<script runat="server">
public static readonly string path = HttpContext.Current.Server.MapPath(".") + "\\IPRecord.txt";
void Application_Start(object sender, EventArgs e)
{
StreamWriter sw = File.AppendText(path);
sw.Write("key:");
sw.Write(" Key ");
sw.Write(" value:");
sw.Write(DateTime.Now.ToString());
sw.Write(" 建立 时间: ");
sw.Write(System.DateTime.Now.ToString());
sw.Write(".");
sw.Write(System.DateTime.Now.Millisecond.ToString());
sw.WriteLine("");
sw.Flush();
sw.Close();
HttpRuntime.Cache.Insert("Key", DateTime.Now, null, DateTime.Now.AddSeconds(10),
Cache.NoSlidingExpiration, CacheItemPriority.Default,
new CacheItemRemovedCallback(onRemove));
}
static void onRemove(string key, Object item, CacheItemRemovedReason reason)
{
StreamWriter sw = File.AppendText(path);
sw.Write("key:");
sw.Write(key);
sw.Write(" value:");
sw.Write(item.ToString());
sw.Write(" 移除 时间: ");
sw.Write(System.DateTime.Now.ToString());
sw.Write(".");
sw.Write(System.DateTime.Now.Millisecond.ToString());
sw.WriteLine("");
sw.Flush();
sw.Close();
HttpRuntime.Cache.Insert("Key", DateTime.Now, null, DateTime.Now.AddSeconds(10),
Cache.NoSlidingExpiration, CacheItemPriority.Default,
new CacheItemRemovedCallback(onRemove));
}
void Application_End(object sender, EventArgs e)
{
// 在应用程序关闭时运行的代码
}
void Application_Error(object sender, EventArgs e)
{
// 在出现未处理的错误时运行的代码
}
void Session_Start(object sender, EventArgs e)
{
// 在新会话启动时运行的代码
}
void Session_End(object sender, EventArgs e)
{
// 在会话结束时运行的代码。
// 注意: 只有在 Web.config 文件中的 sessionstate 模式设置为
// InProc 时,才会引发 Session_End 事件。如果会话模式设置为 StateServer
// 或 SQLServer,则不会引发该事件。
}
</script>