仓酷云

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 2285|回复: 18
打印 上一主题 下一主题

[学习教程] ASP网页编程之在耳目数统计内情

[复制链接]
简单生活 该用户已被删除
跳转到指定楼层
楼主
发表于 2015-2-3 23:39:23 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
只要你想学,就没什么优缺点,上面那位大哥已经把网上的评论说了,但我认为想学哪个都一样,不然它就不可能在当今时代数字艺术方面存活到今天统计|在线|在耳目数   Like most of our topics, I'm covering this one due to user demand for it. If you've been to any one of a few dozen ASP-based sites recently, you've probably seen an example of the script we've going to cover in this article.  It's the little line at the top of these pages saying something like "There are 28 users currently on this site!" It's sort of cute and it gives you an idea of how many people are using the site.  I've even seen one go so far as to show you a list of where people are on the site.  While it's not something that we've chosen to implement, there seems to be enough interest that we thought we should address it.  Normally I'd cover a topic like this in a sample, but since the bulk of this code needs to go into your global.asa file, I thought I should probably give a more in depth explanation.

What are we counting?

It seems to be a silly question.  After all, we just said we were going to count active users.  Well what exactly is an active user? A connection using HTTP (the protocol of the web) isn't like other connections.  FTP, Telnet, E-mail, and most other types of connections are started when a user first visits and ended when the user leaves.  HTTP doesn't work this way.  The connection is made, the request for the page is sent, and the connection is dropped.  This makes getting the number of people currently "on" a site rather difficult.  You don't have a connection to everyone so you can't simply count them.  You also have no way of telling if they're going to come back and request another page or not until they do or until you decide you've waited long enough that they aren't going to!

Here comes ASP with a solution!

The Session object.  All the Session Object does is provide us with a temporary storage area on the server for each user.  It keeps track of which user belongs to which storage area by using cookies.  These cookies never have their expiration property set and as a result, expire as soon as you close your browser.  Unfortunately, because the Session object relies on cookies, if a visitor's browser doesn't support them or has them turned off, each request is looked upon as a new session and can cause problems for a site which uses a lot of Session objects or does a lot of processing in Session_OnStart.  It also causes a script like this to count every hit as a session! This is the main reason we don't like this script too much and haven't used it. The good news is, that for the most part, the fear associated with cookies has been somewhat lessened through user education and the number of users who go out of their way to turn cookies off has decreased significantly.

ASA, I thought they were ASPs!

This brings our discussion to a very special file in your web project: global.asa.  Global.asa is the file that defines a web application.  It contains special scripts called event handlers.  There are four such scripts possible with the current version of ASP.  These are Application_OnStart, Session_OnStart, Session_OnEnd, and Application_OnEnd.  The Application_OnStart script is called when you first start the web application by requesting the first .asp file from it.  The Application_OnEnd occurs when you shut down the web server (but may not be called if the server freezes up or loses power).  As you might expect by now, Session_OnStart occurs when a user requests their first ASP page.  But when does Session_OnEnd run?  The OnEnd event runs when the session ends which can occur in a couple different ways.  The first one is you can call the Abandon method of the Session object which will kill the session immediately.  The second is you can wait for the session to timeout.  This will take however many minutes you've set the Session.Timeout property to.  (The default is 20 if no one's changed it.)   Naturally, it's more desirable to call Session.Abandon and have the Session destroyed immediately and free up the resources it uses instead of letting it use them for 20 minutes.

Now to our user count!

Like I mentioned earlier most of the code for this particular script needs to go into your global.asa file.  For reference, I'm including a global.asa, which includes all the pieces needed to get this script working, below:

Global.asa:
<SCRIPT LANGUAGE="VBScript" RUNAT="Server">

Sub Application_OnStart
    ' Set our user count to 0 when we start the server
    Application("ActiveUsers&quot</p>  强大的可扩展性。ASP具有强大的扩展性,可以实现与多种网络、硬件设备的连接:通过专用的通讯线路远程接入企业; 通过远程拨号服务器为远程拨号客户提供服务;通过WAP为移动电话互联网客户服务。
深爱那片海 该用户已被删除
沙发
发表于 2015-2-4 04:50:25 | 只看该作者
还有如何才能在最短的时间内学完?我每天可以有效学习2小时,双休日4小时。
冷月葬花魂 该用户已被删除
板凳
发表于 2015-2-9 15:57:32 | 只看该作者
代码的可重用性差:由于是面向结构的编程方式,并且混合html,所以可能页面原型修改一点,整个程序都需要修改,更别提代码重用了。
飘飘悠悠 该用户已被删除
地板
发表于 2015-2-16 11:19:36 | 只看该作者
没有坚实的理论做基础,那么我们连踏入社会第一步的资本都没有,特别对于计算机专业的学生学好专业知识是置关重要的。在这里我侧重讲一下如何学习ASP,从平时的学习过程中。
不帅 该用户已被删除
5#
发表于 2015-3-3 01:05:18 | 只看该作者
尽管MS自己讲C#内核中更多的象VC,但实际上我还是认为它和Java更象一些吧。首先它是面向对象的编程语言,而不是一种脚本,所以它具有面向对象编程语言的一切特性,比如封装性、继承性、多态性等等,这就解决了刚才谈到的ASP的那些弱点。
小妖女 该用户已被删除
6#
发表于 2015-3-8 18:43:34 | 只看该作者
ASP(ActiveServerPages)是Microsfot公司1996年11月推出的WEB应用程序开发技术,它既不是一种程序语言,也不是一种开发工具,而是一种技术框架,不须使用微软的产品就能编写它的代码,能产生和执行动态、交互式、高效率的站占服务器的应用程序。
变相怪杰 该用户已被删除
7#
发表于 2015-3-14 11:20:42 | 只看该作者
运用经典的例子。并且自己可以用他来实现一些简单的系统。如果可以对他进行进一步的修改,找出你觉得可以提高性能的地方,加上自己的设计,那就更上一个层次了,也就会真正地感到有所收获。
老尸 该用户已被删除
8#
发表于 2015-3-17 08:08:51 | 只看该作者
不能只是将它停留在纸上谈兵的程度上。
灵魂腐蚀 该用户已被删除
9#
发表于 2015-3-23 22:59:18 | 只看该作者
交流是必要的,不管是生活还是学习我们都要试着去交流,通过交流我们可以学到很多我们自己本身所没有的知识,可以分享别人的经验甚至经历。
蒙在股里 该用户已被删除
10#
发表于 2015-3-27 15:08:41 | 只看该作者
学习是为了用的,是为了让你的程序产生价值,把握住这个原则会比较轻松点。除此之外,课外时间一定要多参加一些社会实践活动,来锻炼自己的能力。
乐观 该用户已被删除
11#
发表于 2015-4-10 16:54:03 | 只看该作者
多看多学多思。多看一些关于ASP的书籍,一方面可以扩展知识面一方面可以鉴借别人是如何掌握、运用ASP的;多学善于关注别人,向同学老师多多学习,不论知识的大小;多思则是要将学到的知识灵活运用。
第二个灵魂 该用户已被删除
12#
发表于 2015-4-12 16:49:07 | 只看该作者
用户端的浏览器不需要提供任何别的支持,这样大提高了用户与服务器之间的交互的速度。
谁可相欹 该用户已被删除
13#
发表于 2015-4-27 10:20:17 | 只看该作者
还有如何才能在最短的时间内学完?我每天可以有效学习2小时,双休日4小时。
金色的骷髅 该用户已被删除
14#
发表于 2015-5-6 21:09:48 | 只看该作者
以上是语言本身的弱点,在功能方面ASP同样存在问题,第一是功能太弱,一些底层操作只能通过组件来完成,在这点上是远远比不上PHP/JSP,其次就是缺乏完善的纠错/调试功能,这点上ASP/PHP/JSP差不多。
只想知道 该用户已被删除
15#
发表于 2015-6-25 16:09:28 | 只看该作者
ASP的语言不仅仅只是命令格式差不多,而是包含在<%%>之内的命令完全就是VB语法。虽然ASP也是做为单独的一个技术来提出的,但他就是完全继承了VB所有的功能。
精灵巫婆 该用户已被删除
16#
发表于 2015-7-7 15:01:04 | 只看该作者
运用ASP可将VBscript、javascript等脚本语言嵌入到HTML中,便可快速完成网站的应用程序,无需编译,可在服务器端直接执行。容易编写,使用普通的文本编辑器编写,如记事本就可以完成。由脚本在服务器上而不是客户端运行,ASP所使用的脚本语言都在服务端上运行。
海妖 该用户已被删除
17#
发表于 2015-7-7 22:49:35 | 只看该作者
掌握asp的特性而且一定要知道为什么。
透明 该用户已被删除
18#
发表于 2015-7-8 19:05:11 | 只看该作者
我就感觉到ASP和一些常用的数据库编程以及软件工程方面的思想是非常重要的。我现在也在尝试自己做网页,这其中就用到了ASP,我想它的作用是可想而知的。
若天明 该用户已被删除
19#
发表于 2015-7-9 07:19:54 | 只看该作者
我认为比较好的方法是找一些比较经典的例子,每个例子比较集中一种编程思想而设计的。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|仓酷云 鄂ICP备14007578号-2

GMT+8, 2024-12-22 17:58

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表