欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

記錄游客頁(yè)面訪問(wèn)IP的簡(jiǎn)易實(shí)現(xiàn)代碼 (asp.net+txt)

 更新時(shí)間:2010年01月15日 17:12:12   作者:  
記錄游客頁(yè)面訪問(wèn)IP的簡(jiǎn)易實(shí)現(xiàn) (asp.net for notepad)
記錄處理類
復(fù)制代碼 代碼如下:

using System;
using System.IO;

/// <summary>
/// File
/// </summary>
public class File
{
protected string FilePath;

/// <summary>
/// File構(gòu)造
/// </summary>
/// <param name="filePath">需要操作的文本路徑</param>
public File(string filePath)
{
this.FilePath = filePath;
}

/// <summary>
/// 文本內(nèi)容寫(xiě)入
/// </summary>
/// <param name="info">寫(xiě)入內(nèi)容</param>
public void FileWrite(string info)
{
try
{
FileInfo file = new FileInfo(FilePath);

if (!file.Exists)
{
using (StreamWriter sw = file.CreateText())
{
sw.WriteLine(info);
}
}
else
{
using (StreamWriter sw = file.AppendText())
{
sw.WriteLine(info);
}
}
}
catch(FileNotFoundException fileCe)
{
throw fileCe;
}
catch (Exception ce)
{
throw ce;
}
}
}

頁(yè)面調(diào)用代碼
復(fù)制代碼 代碼如下:

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//判斷當(dāng)前用戶是否訪問(wèn)過(guò),只記錄未訪問(wèn)過(guò)的用戶
if (Request.Cookies["IsExitsIP"] == null)
{
//每天一個(gè)記事本.txt
string fileName = string.Format("{0}{1}{2}", DateTime.Now.Year.ToString(), DateTime.Now.Month.ToString(), DateTime.Now.Day.ToString());
File file = new File(Server.MapPath("~/test/" + fileName + ".txt"));
file.FileWrite(Request.UserHostName);
//給正在訪問(wèn)的用戶添加已訪問(wèn)標(biāo)記
HttpCookie cokie = new HttpCookie("IsExitsIP");
cokie.Values.Add("ip", Request.UserHostName);
Response.AppendCookie(cokie);
}
}
}
}

相關(guān)文章

最新評(píng)論