Record Processing class
Copy Code code as follows:
Using System;
Using System.IO;
<summary>
File
</summary>
public class File
{
protected string FilePath;
<summary>
File construction
</summary>
<param name= "FilePath" > Text path required for action </param>
Public File (String filePath)
{
This. FilePath = FilePath;
}
<summary>
Text content Write
</summary>
<param name= "Info" > Write content </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;
}
}
}
Page Call Code
Copy Code code as follows:
Public partial class _default:system.web.ui.page
{
protected voi d Page_Load (object sender, EventArgs e)
{
if (! IsPostBack)
{
///To determine whether the current user has been visited, to record only the users that have not been accessed
if (request.cookies["isexitsip"] = = null)
{
//daily Notepad . 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);
//Add an access token to the user being accessed
HttpCookie Cokie = new HttpCookie ("Isexitsip");
Cokie. Values.add ("IP", request.userhostname);
Response.appendcookie (Cokie);
}
}
}
}