記錄游客頁(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)
記錄處理類
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)用代碼
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);
}
}
}
}
復(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)文章
Asp.net使用SignalR實(shí)現(xiàn)消息提醒
這篇文章主要為大家詳細(xì)介紹了Asp.net使用SignalR實(shí)現(xiàn)消息提醒的相關(guān)資料,需要的朋友可以參考下2016-04-04.NET與樹(shù)莓派控制彩色燈帶WS28XX的實(shí)現(xiàn)
這篇文章主要為大家介紹了.NET與樹(shù)莓派控制彩色燈帶WS28XX的實(shí)現(xiàn)過(guò)程,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步早日升職加薪2022-04-04asp.net編程實(shí)現(xiàn)刪除文件夾及文件夾下文件的方法
這篇文章主要介紹了asp.net編程實(shí)現(xiàn)刪除文件夾及文件夾下文件的方法,涉及asp.net針對(duì)文件與目錄的遍歷及刪除操作實(shí)現(xiàn)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-11-11使用 Visual Studio 的“代碼度量值”來(lái)改進(jìn)代碼質(zhì)量
代碼度量是一組軟件度量值,使開(kāi)發(fā)人員可以更好地了解他們正在開(kāi)發(fā)的代碼.這篇文章主要介紹了通過(guò) Visual Studio 的“代碼度量值”來(lái)改進(jìn)代碼質(zhì)量,需要的朋友可以參考下2017-11-11Asp.Net分頁(yè)和AspNetPager控件的使用
在Asp.Net中對(duì)頁(yè)面分頁(yè)的方法很多,可以直接用sql語(yǔ)句分,也可以使用.net提供的PageDataSource類來(lái)分頁(yè),顯示的視圖同樣可以使用第三方控件AspNetPager等來(lái)顯示。2011-02-02.net中實(shí)現(xiàn)listBox左右移動(dòng)
這里給大家推薦的是一段網(wǎng)友分享的,使用.net實(shí)現(xiàn)listBox左右移動(dòng)的代碼,簡(jiǎn)單實(shí)用,這里記錄下來(lái),有需要的小伙伴參考下吧。2015-03-03.Net Core使用OpenXML導(dǎo)出、導(dǎo)入Excel
這篇文章主要為大家詳細(xì)介紹了.Net Core使用OpenXML導(dǎo)出、導(dǎo)入Excel的方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-04-04MultiLine 換行后實(shí)現(xiàn)讀取不換行的具體思路
輸入內(nèi)容中有換行,保存到數(shù)據(jù)庫(kù),直接查看感覺(jué)沒(méi)有換行,但查詢結(jié)果“以文本格式顯示結(jié)果”你就會(huì)發(fā)現(xiàn) 其實(shí)是有換行的,下面與大家分享下具體的解決方法2013-06-06