动态网站制作指南 [  QQ表情  ]
[ 投票调查 ]
[ 企业邮箱 ]
[ 网站空间 ]
网络编程 | 站长之家 | 网页制作 | 图形图象 | 操作系统 | 冲浪宝典 | 软件教学 | 网络办公 | 邮件系统 | 网络安全 | 认证考试 | 系统进程
ASP源码 | .Net源码 | PHP源码 | JSP源码 | JAVA源码 | CGI源码 | VB源码 | C++源码 | Delphi源码 | PB源码 | VF源码 | 汇编 | 服务器
Firefox | IE | Maxthon | 迅雷 | 电驴 | BitComet | FlashGet | QQ | QQ空间 | Vista | 输入法 | Ghost | Word | Excel | wps | Powerpoint
asp | .net | php | jsp | Sql | c# | Ajax | xml | Dreamweaver | FrontPages | Javascript | css | photoshop | fireworks | Flash | Cad | Discuz!
当前位置 > 网站建设学院 > 网络编程 > ASP实例
Tag:注入,存储过程,分页,安全,优化,xmlhttp,fso,jmail,application,session,防盗链,stream,无组件,组件,md5,乱码,缓存,加密,验证码,算法,cookies,ubb,正则表达式,水印,索引,日志,压缩,base64,url重写,上传,控件,Web.config,JDBC,函数,内存,PDF,迁移,结构,破解,编译,配置,进程,分词,IIS,Apache,Tomcat,phpmyadmin,Gzip,触发器,socket
网络编程:ASP教程,ASP.NET教程,PHP教程,JSP教程,C#教程,数据库,XML教程,Ajax,Java,Perl,Shell,VB教程,Delphi,C/C++教程,软件工程,J2EE/J2ME,移动开发
文章搜索服务
邮件订阅
输入你的邮件地址,
你将不会错过任何关于:
[ ASP实例 ]的信息

本月文章推荐
.用Asp备份与恢复SQL Server 数据.
.用ASP+XML打造留言本(4).
.实例演练ASP+XML编程(1).
.一个漂亮的点击计数器.
.使用 ASP+ 列表绑定控件(下).
.网上“店铺”DIY(2).
.创建 Visual Basic COM 组件在 A.
.ASP无组件上载,带进度条,多文件上.
.dreamweaverMX通用分页代码研究.
.用ASP+SQL Server为网页建一道防.
.制作我们自己的Ebay(拍卖系统)(5).
.一个基于ASP的标题广告管理系统(.
.利用ASP实现三个强大功能之二.
.用ASP实现电子贺卡.
.Flash+ASP实现电子互动地图在线标.
.ASP进阶之文章在线管理更新(1).
.用多种方法制作WEB页面的计数器.
.把文件存进access数据库然后取出.
.ASP服务器组件的编程.
.一个基于web的QQ程序 2(xml+asp.

ASP.NET: XML计数器第二版

发表日期:2001-6-8 |


Code:
1) counter.aspx :- The Counter Page

<%@ Import Namespace="System.IO" %>
<%@ Assembly Name="System.Xml" %>
<%@ Import Namespace="System.Xml" %>
<%@ page language="c#" EnableSessionState="True" %>
<%-- These are the imported assembiles and namespaces need to run the counter --%>
<html>
<head>
<title>Saurabh's XML Counter Script</title>
<script language="C#" runat="server">
//script is called when the page is loaded
public void Page_Load(Object src, EventArgs e)
{
//the path to the Xml file which will contain all the data
//modify this if you have any other file or directory mappings.
//modify this if you have been directed here from Step 2 of the ReadMe file.
string datafile="db/xmlcounter.xml" ;

if(!Page.IsPostBack){
//try-catch block containing the counter code
try {
//create an instance of the class XmlDocument
XmlDocument xmldocument = new XmlDocument() ;

//Open a FileStream to the specified file
FileStream fin ;
//It is very Important to specify the "FileShare.ReadWrite" option.
//This allows other viewers to also read and write to the Database
//This was missing in my last release hence there was a BUG !!!
fin = new FileStream(Server.MapPath(datafile), FileMode.Open, FileAccess.Read,
FileShare.ReadWrite) ;
//Load the Document
xmldocument.Load(new StreamReader(fin)) ;
fin.Close();
//create an instance of the DocumentNavigator class used to
//navigate through and XML file
DocumentNavigator navigator = new DocumentNavigator(xmldocument) ;

//Move to the first element (in my file 'Visitors')
navigator.MoveToDocumentElement() ;
//move to it child at position '0' (ie.in my file 'total' node)
navigator.MoveToChild(0) ;

//check if we are on the right element which has an attribute
if (navigator.HasAttributes) {
//get the attribute of the node 'total' called 'tot' (see the xmlcounter.xml file)
//since the value stored is in a string format we 'cast' it into a Int type
int total = int.Parse(navigator.GetAttribute("tot")) ;
//increase the counter
total++ ;
//show the counter on the page
countmess.Text = "You are visitor No: "+total.ToString() ;
//save the incremented counter back in the XML file
navigator.SetAttribute(0,total.ToString() );
}

//Update the Database only if a new session is there
if(Session["counter"]==null)
{
//move back to the Document element
navigator.MoveToDocumentElement() ;
navigator.MoveToChild(0) ;
//then insert the element after the 'total' element which will contain all
//the information of a single visitor
navigator.Insert(TreePosition.After , XmlNodeType.Element, "Viewer","","") ;
//make an instance to the HttpUrl class to get information of the referrer to
//the page if any. if there are no referrers then by Default this object is 'null'
//so we have to make a check if it is null and do the needful
HttpUrl objUrl = Request.UrlReferrer;
if(objUrl!=null)
{
navigator.Insert(TreePosition.FirstChild, XmlNodeType.Element,"Referrer","","");
navigator.Insert(TreePosition.FirstChild, XmlNodeType.Text,"Referrer","","") ;
navigator.Value = objUrl.Host ;
}
else
{
navigator.Insert(TreePosition.FirstChild, XmlNodeType.Element,"Referrer","","");
navigator.Insert(TreePosition.FirstChild, XmlNodeType.Text,"Referrer","","") ;
navigator.Value = "Direct" ;
}
//release the resource for Garbage collection
objUrl=null ;
//move to parent node and then insert the information about the useragent
navigator.MoveToParent() ;
navigator.Insert(TreePosition.After, XmlNodeType.Element,"UserAgent","","" ) ;
navigator.Insert(TreePosition.FirstChild, XmlNodeType.Text,"UserAgent","","" ) ;
navigator.Value = Request.UserAgent ;
navigator.MoveToParent() ;
navigator.Insert(TreePosition.After, XmlNodeType.Element,"UserHostAddress","","" ) ;
navigator.Insert(TreePosition.FirstChild, XmlNodeType.Text,"UserHostAddress","","" ) ;
navigator.Value = Request.UserHostAddress ;
navigator.MoveToParent() ;
navigator.Insert(TreePosition.After, XmlNodeType.Element,"UserHostName","","" ) ;
navigator.Insert(TreePosition.FirstChild, XmlNodeType.Text,"UserHostName","","" ) ;
navigator.Value = Request.UserHostName ;
//to get more information of the users browsers capabilities make an object
//of the HttpBrowserCapabilities class
HttpBrowserCapabilities bc = Request.Browser;

navigator.MoveToParent() ;
navigator.Insert(TreePosition.After, XmlNodeType.Element,"BrowserType","","" ) ;
navigator.Insert(TreePosition.FirstChild, XmlNodeType.Text,"BrowserType","","" ) ;
navigator.Value = bc.Type ;

navigator.MoveToParent() ;
navigator.Insert(TreePosition.After, XmlNodeType.Element,"BrowserName","","" ) ;
navigator.Insert(TreePosition.FirstChild, XmlNodeType.Text,"BrowserName","","" ) ;
navigator.Value = bc.Browser ;

navigator.MoveToParent() ;
navigator.Insert(TreePosition.After, XmlNodeType.Element,"MajorVersion","","" ) ;
navigator.Insert(TreePosition.FirstChild, XmlNodeType.Text,"MajorVersion","","" ) ;
navigator.Value = bc.MajorVersion.ToString() ;

navigator.MoveToParent() ;
navigator.Insert(TreePosition.After, XmlNodeType.Element,"MinorVersion","","" ) ;
navigator.Insert(TreePosition.FirstChild, XmlNodeType.Text,"MinorVersion","","" ) ;
navigator.Value = bc.MinorVersion.ToString(); ;

navigator.MoveToParent() ;
navigator.Insert(TreePosition.After, XmlNodeType.Element,"Platform","","" ) ;
navigator.Insert(TreePosition.FirstChild, XmlNodeType.Text,"Platform","","" ) ;
navigator.Value = bc.Platform ;

//Make an object of the DateTime class to get the Date Time
DateTime now = DateTime.Now ;
navigator.MoveToParent() ;
navigator.Insert(TreePosition.After, XmlNodeType.Element,"Date","","" ) ;
navigator.Insert(TreePosition.FirstChild, XmlNodeType.Text,"Date","","" ) ;
navigator.Value = now.ToShortDateString() ;

navigator.MoveToParent() ;
navigator.Insert(TreePosition.After, XmlNodeType.Element,"Time","","" ) ;
navigator.Insert(TreePosition.FirstChild, XmlNodeType.Text,"Time","","" ) ;
navigator.Value = now.ToShortTimeString() ;
//Create a File Stream again to Write to the Database
//Again remember to specify the "FileShare.ReadWrite"
FileStream fout ;
fout = new FileStream(Server.MapPath(datafile), FileMode.Open, FileAccess.Write,
FileShare.ReadWrite) ;

//finally save the user data to the xml database file
xmldocument.Save(new StreamWriter(fout)) ;
//free the resources explicitly for other classes to use
fout.Close();
navigator=null ;
xmldocument=null ;
//Just store any value to the session
Session["counter"]=1 ;
}

}
catch(Exception edd)
{
//catch other exceptions
Response.Write("<font color=#FF0000>An Exception Occurred "+edd.ToString()+"</font>") ;
}

}
}

</script>
</head>

<body >

<h3 align="center">Welcome to Saurabh's Counter Script</h3>
<br>
<p align="center">
This is a sample page which has the counter scripting in it.
Take the script from this page and paste it on your page.

</p>
<asp:label text="You are visitor No: 0" style="font-size:28pt" id="countmess" runat="server" />


</body>

</html>





2) viewcounter.aspx : The counter information viewing page

<%@ Import Namespace="System" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Data" %>
<%@ Assembly Name="System.Xml" %>
<%@ Import Namespace="System.Xml" %>
<%@ Page Language="C#" %>
<html>
<head>
<title>Saurabh's XML Counter Script</title>
<script language="C#" runat=server>
//this script is execute when the page is loaded
public void Page_Load(Object sender, EventArgs e)
{
//the path to the Xml file which will contain all the data
//modify this if you have any other file or directory mappings.
//modify this if you have been directed here from Step 2 of the ReadMe file.
string datafile="db/xmlcounter.xml" ;
try
{
//Make an instance of the XmlDataDocument class which reads data from a
//xml file and stores it in an DataSet object
XmlDataDocument datadoc = new XmlDataDocument();

//Open a FileStream to the Database
//"FileShare.ReadWrite" enables other user to also read and write to the file
FileStream fin ;
fin = new FileStream(Server.MapPath(datafile), FileMode.Open, FileAccess.Read, FileShare.ReadWrite) ;
// Infer the DataSet schema from the XML data and load the XML Data
datadoc.DataSet.ReadXml(new StreamReader(fin));
//Close the stream
fin.Close();

//get the total no of viewers by getting the count of the no of rows present
//in the Table
showtotal.Text ="Total Viewers :"+ datadoc.DataSet.Tables[1].Rows.Count.ToString() ;

//databind the Repeater to the Dataset of table '1' ie the 'Viewer'
MyDataList.DataSource = datadoc.DataSet.Tables[1].DefaultView;
MyDataList.DataBind();

//free the resources
datadoc=null ;

}
catch (Exception ed)
{
//if there is any exception then display it
Response.Write("<font color=#FF0000>An Exception occured "+ed.ToString()+"</font>") ;
}
}
</script>
</head>
<body >
<h4>Welcome to Saurabh's XML Counter Viewing Page.</h4>
<asp:label id="showtotal" text="" runat="server" />
<br>

<ASP:Repeater id="MyDataList" runat="server">
<template name="headertemplate">
<h5> Viewer Details </h5>
</template>
<template name="itemtemplate">
<br>
<table class="mainheads" width="60%" style="font: 8pt verdana" >
<tr style="background-color:#FFFFCC">
<td>Referrer :</td>
<td>
<%# DataBinder.Eval(Container.DataItem, "Referrer") %>
</td></tr>
<tr style="background-color:#FFFFCC">
<td>User Agent :</td>
<td>
<%# DataBinder.Eval(Container.DataItem, "UserAgent") %>
</td></tr>
<tr style="background-color:#FFFFCC">
<td>User Host Address :</td>
<td>
<%# DataBinder.Eval(Container.DataItem, "UserHostAddress") %>
</td></tr>
<tr style="background-color:#FFFFCC">
<td>User Host Name :</td>
<td>
<%# DataBinder.Eval(Container.DataItem, "UserHostName") %>
</td></tr>
<tr style="background-color:#FFFFCC">
<td>Browser Type :</td>
<td>
<%# DataBinder.Eval(Container.DataItem, "BrowserType") %>
</td></tr>
<tr style="background-color:#FFFFCC">
<td>Browser Name :</td>
<td>
<%# DataBinder.Eval(Container.DataItem, "BrowserName") %>
</td></tr>
<tr style="background-color:#FFFFCC">
<td>Major Version :</td>
<td>
<%# DataBinder.Eval(Container.DataItem, "MajorVersion") %>
</td></tr>
<tr style="background-color:#FFFFCC">
<td>Minor Version :</td>
<td>
<%# DataBinder.Eval(Container.DataItem, "MinorVersion") %>
</td></tr>
<tr style="background-color:#FFFFCC">
<td>Platform :</td>
<td>
<%# DataBinder.Eval(Container.DataItem, "Platform") %>
</td></tr>
<tr style="background-color:#FFFFCC">
<td>Date :</td>
<td>
<%# DataBinder.Eval(Container.DataItem, "Date") %>
</td></tr>


<tr style="background-color:#FFFFCC">
<td>Time :</td>
<td>
<%# DataBinder.Eval(Container.DataItem, "Time") %>
</td>
</tr>
</table><br>
</template>
</ASP:Repeater>
</body>
</html>


上一篇:用asp怎样编写文档搜索页面(6) 人气:9895
下一篇:ASP.NET: XML留言版第二版 人气:14670
浏览全部的内容 Dreamweaver插件下载 常用网页广告代码全集
  最新网站源码 最新软件下载
2008-11-22 CMS001 v2.2 bulid 081122 Beta
2008-11-22 腾讯小说小偷 v5.0 20081113
2008-11-22 iestore网上商店系统 v1.0.7.0
2008-11-22 GKEE CRM客户管理系统 v1.2
2008-11-22 shopd1网店系统 v1.3
2008-11-22 翎风个人主页管理系统 v1.5
2008-11-22 开良狗狗影视搜索小偷 v1.1
2008-11-22 XtreMedia
2008-11-22 互联网数据分享应用平台 v1.0.0
2008-11-21 傲游(Maxthon) 2.1.5 正式版
2008-11-21 Skype v3.8.0.188 Final
2008-11-21 AirPlay OpenAlpha 2008.11.20
2008-11-21 屏幕文字抓取工具 DWMouse1.3.510
2008-11-21 Vista一键还原(Vista Ghost)1.
2008-11-21 SP Photo Fix照片修改1.2破解版
2008-11-21 QQ腾讯聊天工具 v1.2正式版
2008-11-21 FlightTrack航班信息v1.0破解版
2008-11-21 RealPiano仿真钢琴1.0破解版
  发表评论
姓 名: 验证码:
内 容:
站长工具:网站收录查询 | Google PR查询 | ALEXA排名查询 | CSS在线编辑器 | 广告代码 | js/vbs加密 | md5加密 | 进制转换 | UTF-8 转换工具 | Html转换js | Html转换asp | Html转换php | Html转换perl
实用工具:汉字翻译拼音 | 拼音字典 | 符号对照表 | 个税计算 | 实时汇率查询换算 | 经典小工具 | 汉字简繁转换 | 普通单位换算 | 公制单位换算 | 生辰老黄历 | 国内电话区号 | 国家代码与域名缩写 | 文字加密解密 | 健康查询 | 万年历 | 汉字横竖排版 | 手机号码查询 | 计算器 | ip搜索
业务联系 | 广告刊登 | 频道合作 | 投稿荐稿 | 联系方式 | 加入收藏 | RSS订阅
Copyright © 2000-2008 www.knowsky.com All rights reserved | 网络实名:动态网站制作指南 | 沪ICP备05001343号
ホームページ制作 不動産検索システム 求人情報
防水工事·改修工事 フットサル大会 探偵
SEO対策 中国語教室 ホームページ作成