仓酷云

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

[学习教程] ASP网页编程之处置Asp中的毛病

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

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

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

x
大家可以自己去看一看.可以说看得想呕吐.以前有次下了个动网来看.里面连基本内置函数的保护措施(函数没防御性)都没有.难怪经常补这个补那个了.可能现在.NET版会好点吧毛病   You just finished your ASP application in time, barely making the dealine! As you upload the final version to the webserver, you receive an email from your supervisor indicating that he's ready for your demo. You confidently stride into his office and give him instructions on accesses the application through the Intranet.

Your boss comes to the first page, and is asked to enter his name. You've created a slick, customized feel to the site, recording the user and his or her preferences in a database. Your boss types in his name, "The Pointy Haired Boss," and hits the submit button. Instead of being taken to the next page, he sees the following text pop up on the screen:

Microsoft OLE DB Provider for ODBC Drivers error ' 80004005' [Microsoft][ODBC Access 97 ODBC driver Driver] syntax wrong near '

Please note that I just made this error message up, so, please, no emails asking about how one gets this error by entering his name!

You get one of those looks from your boss, a look that says, "I hope you weren't expecting a positive performance review."

There's nothing worse to an end user than to see those dreaded ADO errors. They are misformatted, cryptic, and leave the user wondering what they are suppose to do. Your average end user doesn't know ODBC from OLE. So how can you prevent these nasty error messages?

First you must insert at the top of your ASP page:


<% On Error Resume Next %>
This will tell ASP to just skip over any errors, instead of halting execution and printing out a nasty error message. You may be tempted to leave it at this, although if you do, and errors occur, your users won't be aware of them. They will think their information was correctly saved, when in actuality it wasn't due to an ADO error.

What, then, do we want to do if there is an error? Well, the idea situation would be to let the end user know that an error had occurred and will be worked on, and automatically email technical support with the ADO error messages. So that is what we will do!

The question now is how to we "trap" errors? Well, after any ADO call that accesses the database, we will want to put the following lines:



If Err.number <> 0 then
  TrapError Err.description
End If

You will want to put this after all ADO calls that communicate directly with the database. This includes ConnectionObject.Open, ConnectionObject.Execute, and RecordsetObject.Open. Now, you may be wondering where the sub TrapError is defined: we're about to do that. Create a file called ErrorHandler.asp and put it in your /include or /scripts directory. In ErrorHandler.asp, we will have the following subs:


TrapError
ProcessErrors
Let's look at the code for ErrorHandler.asp:



<%
Dim strErrorMessage
Dim bolErrors

'Initialize variables
strErrorMessage = ""    'The error messages for tech. support
bolErrors = False    'Have we found any errors yet?

'Now our two subs
sub TrapError(strError)
  bolErrors = True    'Egad, we've found an error!

  strErrorMessage = strErrorMessage & strError & ", "
end sub



'If there are any errors, this function will email tech. support
sub ProcessErrors()
  if bolErrors then
    'Send the email
    Dim objCDO
    Set objCDO = Server.CreateObject("CDONTS.NewMail")

    objCDO.To = "techsupport@mysite.com"
    objCDO.From = "techsupport@mysite.com"
    objCDO.Subject = "AN ADO ERROR OCCURRED"
    objCDO.Body = "At " & Now & " the following errors occurred on " & _
          "the page " & Request.ServerVariables("SCRIPT_NAME") & _
          ": " & _
                  chr(10) & chr(10) & strErrorMessage

    objCDO.Send

    Set objCDO = Nothing

    'Now, we've got to print out something for the user
    Response.Write "There has been a database error.  Technical Support " & _
&nbsp</p>  国内有些大的CRM厂商的ASP就写得不错.无论是概念还是它里面用JAVASCRIPT的能力.并不是说现在的程序员用了ASP.NET来写程序就可以说自己高档了
金色的骷髅 该用户已被删除
沙发
发表于 2015-2-4 04:50:11 | 只看该作者
还有如何才能在最短的时间内学完?我每天可以有效学习2小时,双休日4小时。
活着的死人 该用户已被删除
板凳
发表于 2015-2-6 09:38:49 | 只看该作者
掌握asp的特性而且一定要知道为什么。
莫相离 该用户已被删除
地板
 楼主| 发表于 2015-2-15 22:07:58 | 只看该作者
完全不知道到底自己学的是什么。最后,除了教程里面说的几个例子,还是什么都不会。
山那边是海 该用户已被删除
5#
发表于 2015-3-3 20:28:36 | 只看该作者
哪些内置对象是可以跳过的,或者哪些属性和方法是用不到的?
简单生活 该用户已被删除
6#
发表于 2015-3-11 13:09:25 | 只看该作者
下载一个源代码,然后再下载一个VBScript帮助,在源代码中遇到不认识的函数或是其他什么程序,都可以查帮助进行解决,这样学习效率很高。
因胸联盟 该用户已被删除
7#
发表于 2015-3-18 11:57:35 | 只看该作者
下面简单介绍一下我学习ASP的方法,希望对想学习ASP的朋友有所帮助...
爱飞 该用户已被删除
8#
发表于 2015-3-25 20:27:55 | 只看该作者
哪些内置对象是可以跳过的,或者哪些属性和方法是用不到的?
飘灵儿 该用户已被删除
9#
发表于 2015-4-6 17:01:58 | 只看该作者
你可以通过继承已有的对象最大限度保护你以前的投资。并且C#和C++、Java一样提供了完善的调试/纠错体系。
只想知道 该用户已被删除
10#
发表于 2015-4-12 13:55:47 | 只看该作者
我就感觉到ASP和一些常用的数据库编程以及软件工程方面的思想是非常重要的。我现在也在尝试自己做网页,这其中就用到了ASP,我想它的作用是可想而知的。
海妖 该用户已被删除
11#
发表于 2015-4-29 02:19:06 | 只看该作者
兴趣爱好,那么你无须学编程,申请一个域名和空间,在网上下载一些免费开源的CMS系统,你不用改代码,只须熟悉它们的后台操作,像office一样简单方便,很快就能建一个站点,很多站长都是这样做的
不帅 该用户已被删除
12#
发表于 2015-5-1 03:43:06 | 只看该作者
从事这个行业,那么你可以学ASP语言,简单快速上手,熟练dreamweav排版,写asp代码,熟练photoshop处理图片,打好基础就行了
再见西城 该用户已被删除
13#
发表于 2015-5-3 11:38:43 | 只看该作者
在平时的学习过程中要注意现学现用,注重运用,在掌握了一定的基础知识后,我们可以尝试做一些网页,也许在开始的时候我们可能会遇到很多问题,比如说如何很好的构建基本框架。
透明 该用户已被删除
14#
发表于 2015-6-9 23:24:22 | 只看该作者
我们必须明确一个大方向,不要只是停留在因为学而去学,我们应有方向应有目标.
若相依 该用户已被删除
15#
发表于 2015-7-9 05:29:16 | 只看该作者
运用ASP可将VBscript、javascript等脚本语言嵌入到HTML中,便可快速完成网站的应用程序,无需编译,可在服务器端直接执行。容易编写,使用普通的文本编辑器编写,如记事本就可以完成。由脚本在服务器上而不是客户端运行,ASP所使用的脚本语言都在服务端上运行。
乐观 该用户已被删除
16#
发表于 2015-7-11 04:47:31 | 只看该作者
哪些内置对象是可以跳过的,或者哪些属性和方法是用不到的?
蒙在股里 该用户已被删除
17#
发表于 2015-7-12 23:12:26 | 只看该作者
作为IE上广为流传的动态网页开发技术,ASP以它简单易学博得了广大WEB程序爱好这的青睐,而且它对运行环境和开发品台的不挑剔,以及有大量有效的参考手册,极大的推广了它的发展。
老尸 该用户已被删除
18#
发表于 2015-10-7 16:35:54 | 只看该作者
没有坚实的理论做基础,那么我们连踏入社会第一步的资本都没有,特别对于计算机专业的学生学好专业知识是置关重要的。在这里我侧重讲一下如何学习ASP,从平时的学习过程中。
小妖女 该用户已被删除
19#
发表于 2015-10-9 10:28:42 | 只看该作者
你可以通过继承已有的对象最大限度保护你以前的投资。并且C#和C++、Java一样提供了完善的调试/纠错体系。
第二个灵魂 该用户已被删除
20#
发表于 2015-10-22 19:53:27 | 只看该作者
从事这个行业,那么你可以学ASP语言,简单快速上手,熟练dreamweav排版,写asp代码,熟练photoshop处理图片,打好基础就行了
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

GMT+8, 2024-4-26 22:36

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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