I have an asp.net web application where I want to store user information when a session start in a text file in my pc. For that I use Global.asax
and its void Session_Start()
method. But when a client access my page over lan, the text file is not created in my pc. Only when I visit my page the file creates. I want my user name, mac address, pages user visited, session start time, session end time in a text file in my pc when clients are accessing my site over lan. I am a beginner at asp.net. So any help will be highly appreciated.
void Session_Start(object sender, EventArgs e)
{
string txtFilePath = @"C:\LogInfo.txt";
StreamWriter w // ???
string hostName =
System.Net.Dns.GetHostEntry(Request.ServerVariables["REMOTE_HOST"]).HostName;
UserInfo userObj = new UserInfo();
string macAddress = userObj.GetMACAddress();
HttpContext context = HttpContext.Current;
string baseURL = context.Request.Url.AbsolutePath;
w = File.CreateText(txtFilePath);//File.AppendText(txtFilePath);
w.Write("Start Log Entry: ");
w.WriteLine("{0} {1}", DateTime.Now.ToLongTimeString(),
DateTime.Now.ToLongDateString());
w.WriteLine("\n");
w.WriteLine("User: {0}", hostName);
w.WriteLine("\nMAC Address: {0}", macAddress);
w.WriteLine("-------------------------------\r\n");
w.Flush();
w.Close();
}