protected void Page_Load(object sender, EventArgs e)
{
string VisitorReferrer;
// Full path to GeoLiteCity.dat file
string FullDBPath = Server.MapPath("~/App_Data/GeoLiteCity.dat");
// Visitor's IP address
string VisitorIP;
VisitorIP = Request.ServerVariables["REMOTE_ADDR"];
if (Request.UrlReferrer != null)
{
VisitorReferrer = Request.UrlReferrer.ToString();
}
else
{
VisitorReferrer = "";
}
// Create objects needed for geo targeting
Geotargeting.LookupService ls = new Geotargeting.LookupService(FullDBPath, Geotargeting.LookupService.GEOIP_STANDARD);
Geotargeting.Location visitorLocation = ls.getLocation(VisitorIP);
DownloadLog myDownloadLog = new DownloadLog();
DownloadLogInfo myDownloadLogInfo = new DownloadLogInfo();
if (visitorLocation != null) // get the geoip information using visitor IP address
{
myDownloadLogInfo.Country = visitorLocation.countryName;
myDownloadLogInfo.CountryCode = visitorLocation.countryCode;
myDownloadLogInfo.City = "unknown";
if (visitorLocation.city != null)
{
myDownloadLogInfo.City = visitorLocation.city;
}
myDownloadLogInfo.IP = VisitorIP;
myDownloadLogInfo.ProductFamilyID = 1;
myDownloadLogInfo.ReferrerURL = VisitorReferrer;
}
else
{
string country = "unknown";
string countryCode = "unknown";
string city = "unknown";
myDownloadLogInfo.Country = country;
myDownloadLogInfo.CountryCode = countryCode;
myDownloadLogInfo.City = city;
myDownloadLogInfo.IP = VisitorIP;
myDownloadLogInfo.ProductFamilyID = 1;
myDownloadLogInfo.ReferrerURL = VisitorReferrer;
}
// WebConfig.Connection is the connection the database and insert data into database
myDownloadLog.Add(myDownloadLogInfo, WebConfig.Connection);
Response.ContentType = "application/zip";
Response.AddHeader("content-disposition", "attachment; filename=softwaresetup.zip");
FileStream sourceFile = new FileStream(@"C:\inetpub\dotnetfish\software\softwaresetup.zip", FileMode.Open);
long FileSize;
FileSize = sourceFile.Length;
byte[] getContent = new byte[(int)FileSize];
sourceFile.Read(getContent, 0, (int)sourceFile.Length);
sourceFile.Close();
Response.BinaryWrite(getContent);
}