访客统计程序demo,框架完成,架构补充我就不爱做了~ 所以就这样~

分类: c# | 标签: | 日期:2010-04-01

Spidertest.aspx

<form id=”form1″>
<div><img src=”http://stats.bordf.com/spider.aspx?site=test” border=”0″ alt=”" width=”0″ height=”0″ /></div>
</form>

spider.aspx

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;

public partial class spider : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

if (!string.IsNullOrEmpty(Request.QueryString["site"]))
{
string site, ip, url, time, agent,content;
site = Request.QueryString["site"];
ip = Request.UserHostAddress.ToString();
if (!string.IsNullOrEmpty(Request.ServerVariables["HTTP_REFERER"]))
{
url = Request.ServerVariables["HTTP_REFERER"].ToString();
}
else
{
url = “null”;
}
time = DateTime.Now.ToString();
agent = Request.UserAgent.ToString();
agent = agen(agent);
content = time + ” ” + url +” “+agent+” ” +ip;
StreamWriter sw = new StreamWriter(Server.MapPath(site + “.txt”), true, System.Text.Encoding.UTF8);
sw.WriteLine(content);
sw.Dispose();

}

}
private string agen(string ag)
{
string agents=”null”;
if (ag.Contains(“Mozilla”) == null)
{
agents = ag;
}

return agents;
}
}

核心在spider.aspx

注意处理!string.IsNullOrEmpty()

对于带参的页面处理,挺好~

声明:本文为耿振的博客 http://blog.bordf.com发布文章。转载务必注明出处

注意:转载须保留全文:请保留本文出处!否则耿振的博客将向你网站的主机商投诉。
本文永久地址:http://blog.bordf.com/387/


表情:<( ̄︶ ̄)> | (⊙ˍ⊙) | >﹏< | b( ̄▽ ̄)d | (─.─||) | (^_-)

[ Ctrl+Enter提交 ]