最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

記錄游客頁面訪問IP的簡易實現(xiàn)代碼 (asp.net+txt)

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

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)容寫入
/// </summary>
/// <param name="info">寫入內(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;
}
}
}

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

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//判斷當前用戶是否訪問過,只記錄未訪問過的用戶
if (Request.Cookies["IsExitsIP"] == null)
{
//每天一個記事本.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);
//給正在訪問的用戶添加已訪問標記
HttpCookie cokie = new HttpCookie("IsExitsIP");
cokie.Values.Add("ip", Request.UserHostName);
Response.AppendCookie(cokie);
}
}
}
}

相關(guān)文章

最新評論

翼城县| 富阳市| 泸州市| 永新县| 兴仁县| 田林县| 罗平县| 伊川县| 舟曲县| 苏州市| 武邑县| 宁陕县| 柏乡县| 汶上县| 南部县| 龙里县| 丹棱县| 景德镇市| 定西市| 乳源| 星座| 同德县| 景洪市| 左云县| 安新县| 屏东市| 中方县| 松滋市| 莒南县| 上思县| 宣汉县| 西林县| 定远县| 太仆寺旗| 宜兰市| 林口县| 南阳市| 青岛市| 托克托县| 当雄县| 竹山县|