简单ASP.NET + XML计数器
2005-07-15 18:30
323 查看
有时要想做一个纯粹的计数流量器,可以采用XML来替代数据库,速度特快.
counter.aspx
<%@ Page Language="C#" Debug="true" codepage="936"%>
<%@ Import Namespace="System"%>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Xml" %>
<script language="c#" runat="server">
//*****************************************************
// 调用方法
// 计数: counter.aspx?count=yes
// 显示: counter.aspx
//*****************************************************
public string Exec = string.Empty;
private void Page_Load(object sender, System.EventArgs e)
{
string fileName = "counter.xml";
string filePath = Server.MapPath(fileName);
if ( File.Exists(filePath) )
{
Exec = Request.QueryString["count"];
if ( Exec != null && Exec != string.Empty )
{
XmlDocument xdoc = new XmlDocument();
try
{
xdoc.Load(filePath);
XmlNodeList xnl = xdoc.GetElementsByTagName("Datas");
XmlNode xn = xnl[0];
XmlNode SettingNode = xn.FirstChild;
int Counts = int.Parse(SettingNode.InnerText) + 1;
SettingNode.InnerText = Counts.ToString();
xdoc.Save(filePath);
}
finally
{
xdoc = null;
}
}
else
{
XmlDocument xdoc = new XmlDocument();
try
{
xdoc.Load(filePath);
XmlNodeList xnl = xdoc.GetElementsByTagName("Datas");
XmlNode xn = xnl[0];
XmlNode SettingNode = xn.FirstChild;
int Counts = int.Parse(SettingNode.InnerText);
Response.Write(Counts.ToString());
}
finally
{
xdoc = null;
}
}
}
else
Response.Write("NOT");
}
</script>
counter.xml
<?xml version="1.0" encoding="utf-8"?>
<DataList>
<Datas>
<Count>0</Count>
</Datas>
</DataList>
counter.aspx
<%@ Page Language="C#" Debug="true" codepage="936"%>
<%@ Import Namespace="System"%>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Xml" %>
<script language="c#" runat="server">
//*****************************************************
// 调用方法
// 计数: counter.aspx?count=yes
// 显示: counter.aspx
//*****************************************************
public string Exec = string.Empty;
private void Page_Load(object sender, System.EventArgs e)
{
string fileName = "counter.xml";
string filePath = Server.MapPath(fileName);
if ( File.Exists(filePath) )
{
Exec = Request.QueryString["count"];
if ( Exec != null && Exec != string.Empty )
{
XmlDocument xdoc = new XmlDocument();
try
{
xdoc.Load(filePath);
XmlNodeList xnl = xdoc.GetElementsByTagName("Datas");
XmlNode xn = xnl[0];
XmlNode SettingNode = xn.FirstChild;
int Counts = int.Parse(SettingNode.InnerText) + 1;
SettingNode.InnerText = Counts.ToString();
xdoc.Save(filePath);
}
finally
{
xdoc = null;
}
}
else
{
XmlDocument xdoc = new XmlDocument();
try
{
xdoc.Load(filePath);
XmlNodeList xnl = xdoc.GetElementsByTagName("Datas");
XmlNode xn = xnl[0];
XmlNode SettingNode = xn.FirstChild;
int Counts = int.Parse(SettingNode.InnerText);
Response.Write(Counts.ToString());
}
finally
{
xdoc = null;
}
}
}
else
Response.Write("NOT");
}
</script>
counter.xml
<?xml version="1.0" encoding="utf-8"?>
<DataList>
<Datas>
<Count>0</Count>
</Datas>
</DataList>
相关文章推荐
- asp.net中xml的简单增删改
- 简单的XML在ASP.NET中增删改应用
- ASP.NET操作简单的xml,增删改查
- [ASP/ASP.net]最简单的XML创建、写入操作
- ASP.NET中实现简单访问统计计数器
- Asp.net简单的视频上传与XML文件增删!(及视频在线转换)
- 简单的XML在ASP.NET中增删改应用
- ASP.NET MVC 生成简单的 xml 权限结构
- ASP.NET和C#中对XML的操作,以及简单的xml与xsl !
- ASP.NET:XML计数器第二版
- 简单的 ASP.NET XML Web 服务
- 利用ASP.NET制作简单计数器的例子
- AJAX学习笔记 一:简单的XMLHTTPRequest示例和asp.net异步更新。
- asp.net MVC中linq to xml的简单操作
- ASP.NET和C#中对XML的操作,以及简单的xml与xsl !
- [ASP/ASP.net]最简单的XML运用
- Asp.Net读写XML简单方法
- 技巧百问(9):ASP.NET和C#中对XML的操作,以及简单的xml与xsl !
- 简单的Asp.net计数器控件
- Asp.Net读写XML简单方法