[4404][ASP][技巧]ASP隱藏式偵錯/追踪技巧
若使用ASP寫網頁,一般來說在正式環境中較不建議將錯誤訊息直接以response.write顯示在網頁上,
但若有須要在不被使用者知道的狀況下偵錯呢?
可以使用:
'==========================================
set fso = CreateObject("Scripting.FileSystemObject")
Set txtStreamOut = fso.OpenTextFile( "D:\webManager\Alex.Log", 2, True)
txtStreamOut.WriteLine "A"
txtStreamOut.WriteLine(URL)
set http=nothing
set fso=nothing
set txtStreamOut=nothing
'==========================================
放在ASP中來偵錯,將須要偵錯的變數在執行網頁時,順便將錯誤存成文字檔,
如此就可以達到不被使用者發覺的目的了
轉貼:midstream之笑拈妙境 https://dotblogs.com.tw/midstream/2013/05/30/105108
2019年6月21日 星期五
2019年6月18日 星期二
建立xml檔案
建立xml檔案,例如sitemap.xml、rss.xml
不要用這個物件去建立 set fs=Server.CreateObject("Scripting.FileSystemObject"),全都是坑你知道麼。
用這個server.CreateObject("adodb.stream"),如下:
filePath=server.MapPath("/sitemap.xml")
BuildFile filePath,str1,"utf-8"
Sub BuildFile(FileUrl,str,CharSet)
set stm=server.CreateObject("adodb.stream")
stm.Type=2 '1-二進制,2-文本
stm.mode=3 '1-讀,2-寫,3-讀寫
stm.charset=CharSet '編碼方式,可選值:ascii,gb2312
stm.open
stm.WriteText str
stm.SaveToFile FileUrl,2
stm.flush
stm.Close
set stm=nothing
end Sub
完畢。
還有很多用途,多看看吧。
2016年8月24日 星期三
監控網站是否正常
public void MonitorWeb(Model.ServiceInfo mServerInfo)
{
var sUrl = mServerInfo.ServiceConfig;
var mLogInfo = new Model.LogInfo { ServiceId = mServerInfo.ServiceId };
try
{
var mWebRequest = (HttpWebRequest)WebRequest.Create(sUrl);
var mWebResponse = (HttpWebResponse)mWebRequest.GetResponse();
if (mWebResponse.StatusCode == HttpStatusCode.OK)
{
mLogInfo.Status = "1";
mLogInfo.Remark = "";
mServerInfo.ErrorCou = 0;
}
else
{
mLogInfo.Status = "0";
mLogInfo.Remark = mWebResponse.StatusDescription;
mServerInfo.ErrorCou = mServerInfo.ErrorCou + 1;
}
mWebResponse.Close();
}
catch (Exception ex)
{
mLogInfo.Status = "0";
mLogInfo.Remark = ex.Message;
mServerInfo.ErrorCou = mServerInfo.ErrorCou + 1;
}
DAL.DbOp.UpdateState(mServerInfo, mLogInfo);
}
{
var sUrl = mServerInfo.ServiceConfig;
var mLogInfo = new Model.LogInfo { ServiceId = mServerInfo.ServiceId };
try
{
var mWebRequest = (HttpWebRequest)WebRequest.Create(sUrl);
var mWebResponse = (HttpWebResponse)mWebRequest.GetResponse();
if (mWebResponse.StatusCode == HttpStatusCode.OK)
{
mLogInfo.Status = "1";
mLogInfo.Remark = "";
mServerInfo.ErrorCou = 0;
}
else
{
mLogInfo.Status = "0";
mLogInfo.Remark = mWebResponse.StatusDescription;
mServerInfo.ErrorCou = mServerInfo.ErrorCou + 1;
}
mWebResponse.Close();
}
catch (Exception ex)
{
mLogInfo.Status = "0";
mLogInfo.Remark = ex.Message;
mServerInfo.ErrorCou = mServerInfo.ErrorCou + 1;
}
DAL.DbOp.UpdateState(mServerInfo, mLogInfo);
}
最重要部份
var mWebRequest = (HttpWebRequest)WebRequest.Create(sUrl);
var mWebResponse = (HttpWebResponse)mWebRequest.GetResponse();
if (mWebResponse.StatusCode == HttpStatusCode.OK)
var mWebResponse = (HttpWebResponse)mWebRequest.GetResponse();
if (mWebResponse.StatusCode == HttpStatusCode.OK)
==================
參考:
http://fecbob.pixnet.net/blog/post/39096667
2015年5月14日 星期四
檔案重新命名
檔案重新命名,用搬移檔案的方式達成。
Syntax
FileSystemObject.MoveFile source,destination
<%
dim fs
set fs=Server.CreateObject("Scripting.FileSystemObject")
fs.MoveFile "c:\web\*.gif","c:\images\"
set fs=nothing
%>
======================================
參考 :
w3c, The FileSystemObject Object
http://www.w3schools.com/asp/asp_ref_filesystem.asp
2015年3月23日 星期一
asp判斷是否為英文或數字
方法一:
方法二:
原先查到的資料是判斷
<% 'Response.Write(isValidate("ac4中123") & "<br>") 'Response.Write(isValidate("ac4123") & "<br>") Function isValidate(str) Dim re Set re = new RegExp re.Pattern = "[^a-zA-Z0-9]" isValidate = re.Test(str) End Function %> |
方法二:
function ContainsChtString(str) dim x,tmp tmp = false for x = 1 to len(str) if asc(mid(str,x,1)) > 32 and asc(mid(str,x,1)) < 127 then tmp = true exit for end if next ContainsChtString= tmp end function if ContainsChtString(Name) then error_mag = "字串包含特殊符號、數字和大小寫英文字" end if |
原先查到的資料是判斷
asc(mid(str,x,1)) < 0 ,ascii碼小於零,即中文字,但後來發現,中文字中間夾英數字,就判斷不出來了。
所以改寫成 asc(mid(str,x,1)) > 32 and asc(mid(str,x,1)) < 127
判斷包含特殊符號、數字和大小寫英文字
================================
如果要判斷是否為數字
IsNumeric()
================================
所以改寫成 asc(mid(str,x,1)) > 32 and asc(mid(str,x,1)) < 127
判斷包含特殊符號、數字和大小寫英文字
================================
如果要判斷是否為數字
IsNumeric()
================================
2015年3月15日 星期日
IUSR & IWAM
IUSR
Internet 來賓帳戶
匿名存取 Internet Information Services 的內建帳戶
IWAM
啟動 IIS 處理程序帳戶
從作業應用程式啟動的內建 Internet Information Services 帳戶
2015年3月12日 星期四
asp實作線上人數
Application 物件的應用
Application 物件可以用來保存總體變數,這些變數將保留到伺服器關機為止,由於這些變數在保存時不會去區分個別用戶端的連線編號(Session ID),因此無論是哪個用戶端都可以讀寫,利用這個特性我們可以很容易開發出計數器與聊天室的功能。
下面的例子,當參觀者連線到首頁時,就累計人數:
<%
Application.Lock
Application("count")=Application("count")+1
Application.Unlock
%>
累計參觀人次:<% =Application("count") %>
在操作 Application 物件時要特別注意寫入衝突的問題,當參觀者同時上線時,由於大家所存取的 Application 變數是同一個,如果不把它鎖定就直接寫入,會造成計數不正確的現象。Application.Lock 就是用來鎖定物件,防止他人寫入。當物件被鎖定時,其他人就會暫停執行程式,等到鎖定解除後才會繼續執行。
如果要製作的計數器是線上人數,則不可以只累加而不減少,正確的作法應該是在參觀者上線時加 1,離線時減 1,特別要注意的是參觀者上線時,並不一定都會去連首頁,所以進行計數的程式不能寫在首頁中,首頁頂多只是用來秀出人數而已。
要達到這個功能必須使用 Session 物件所提供的兩個事件處理器:onStart 和 onEnd,前者在參觀者連線時會自動觸發執行,後者在離線時觸發執行。而要定義這兩個事件處理器,只能將程式寫在 global.asa 檔案中,這個檔案必須建立在網站主目錄的根目錄中,而且一個虛擬站台只能有一份 global.asa。程式語法如下:
<script language="VBScript" runat="SERVER">
SUB Session_onStart
Application.Lock
Application("online")=Application("online")+1
Application.Unlock
END SUB
SUB Session_onEnd
Application.Lock
Application("online")=Application("online")-1
Application.Unlock
END SUB
</script>
global.asa 程式存檔後就會立即生效,現在我們就可以找個適當的網頁,來顯示線上人數:
現在有<% =Application("online") %>人上線
補充說明:Application 物件也有提供 onStart 和 onEnd 事件處理器,前者在 IIS 啟動時自動執行,後者在 IIS 關閉時執行。
來源:
http://www.spps.tp.edu.tw/documents/memo/asp_develop.htm
2015年3月8日 星期日
filesystemobject取得資料夾內的檔案名稱
fPath = Server.MapPath("file\") Set fs=Server.CreateObject("Scripting.FileSystemObject") '擷取使用者上傳檔名 Set folder = fs.GetFolder(fPath) For each f in folder.files fName = f.Name Next set fs=nothing |
2015年3月5日 星期四
將儲存功能寫在另一個asp裡面
將儲存功能寫在另一個asp裡面
完畢。
案例一:
將儲存功能寫在另一個asp裡面,js定義兩個父子視窗關係
在父視窗(f100.asp) 按下儲存按鈕,
利用button onclick開啟子視窗(b010. asp),執行儲存功能,
js關閉子視窗,且重整父視窗。
f100.asp
<form name="frmform" method="post" action="f100.asp?
<input type=button value="儲存" onclick='run_submit();' class="formcss">
'...
</html>
<script language="javascript">
function run_submit(){
var url="b010.asp"
frmform.action=url;
var xwin = Newopenurl("about:blank","
frmform.target = "xwin";
if(xwin.opener==null) xwin.opener=window; //設定新視窗和舊視窗的關係
frmform.submit();
}
</script>
|
b010.asp
'儲存功能
'...
<script language=javascript>
//關閉子視窗,且重整父視窗。
window.close();
window.opener.location.reload(
</script>
|
****************************** ****
案例二:
將儲存功能寫在另一個asp裡面,(不開啟子視窗)
在網頁(watchgrant_f010.asp) 按下儲存按鈕,
導入第二個網頁(watchgrant_q010.asp) 執行儲存功能,
儲存功能執行完畢後,再利用js導回第一個網頁。
註 : 第一個網頁有兩個form,與此案例沒有什麼關係。
f010.asp
<!--撰寫2個form-->
<!--第一個form-->
<form name="form" method="post" action="f010.asp?
<!--第二個form-->
<!--第二個form,將儲存功能寫在另一個asp裡面,--
<form name="form1" method="post" action="q010.asp?id=<%=P_id%>&no=<%
<INPUT class=formcss_other type=submit value="儲存" name=save>
|
q010.asp
'儲存功能
'...
<script language=javascript>
alert ("個人費用登記作業成功!!")
window.location.href="/f010.asp?id=<%=P_
</script>
|
完畢。
2015年2月24日 星期二
瀏覽人次計算
利用Request.ServerVariables("Remote_Addr") 計算瀏覽人次
- 抓取cliend端ip
Request.ServerVariables("Remote_Addr") - 將cliend端ip存入session
- 條件(1或2):
1.判斷比較「cliend端ip」與「session存入的ip」,不相同。
2.判斷session值為空。
執行動作:計數+1。 session存入ip 。 - 完畢。
<% sqlstr = "SELECT top 1 * FROM WebCount" Set Rs = Server.CreateObject("ADODB.Recordset") Rs.open sqlstr,connE, 1, 3 if session("RemoteAddr_E") = "" or session("RemoteAddr_E") <> Request.ServerVariables("Remote_Addr") then Rs("Web_Count") = Rs("Web_Count") + 1 session("RemoteAddr_E") = Request.ServerVariables("Remote_Addr") Rs.update Web_E_Count = "0000000" & Rs("Web_Count") Session("Web_E_Count") = right(Web_E_Count,7) End if Rs.close set Rs = nothing %> |
asp下載遠端檔案的程式碼
<% '將圖片欄位讀出,並存入 strUrl 變數中 Dim strUrl Do While not RS.EOF strUrl = strUrl & RS("图片") RS.MoveNext Loop '將 strUrl 折解,並存入 arrUrl 陣列中 Dim arrUrl arrUrl = Split(strUrl, ";") '1、檢查遠端檔案是否存在,若不存在則警告訊息,但不影響程式進行 '2、檢查本地有否對應目錄,若不存在則建立目錄 '3、將遠端檔案下載到本地 Dim winPath1, winPath2 Dim arrPath Dim FileName Dim i, j Dim Total Dim ErrText winPath1 = "E:\Temp\PULADA\" '此目錄必須自己手動建立 For i = LBound(arrUrl) to UBound(arrUrl) - 1 '將 arrUrl(i) 拆解為另一陣列 arrPath,以便取得完整檔名 arrPath = Split(Replace(arrUrl(i), "http://" , ""), "/") '取得完整檔名 FileName = arrPath(UBound(arrPath)) '1、檢查遠端檔案是否存在,若不存在則警告訊息,但不影響程式進行 Set XMLHTTP = Server.Createobject("MSXML2.ServerXMLHTTP.5.0") XMLHTTP.Open "GET", arrUrl(i), false XMLHTTP.Send() '判斷遠端檔案是否存在,200 代表存在,404 代表不存在 If XMLHTTP.Status <> 200 Then Response.Write "<font color=FF0000>第 " & i + 1 & " 筆:失敗" & "<br>" '記錄錯誤訊息,然後在程式執行完後顯示 ErrText = ErrText & arrUrl(i) & "<br>" Else RemoteFile = XMLHTTP.ResponseBody '2、檢查本地有否對應目錄,若不存在則建立目錄 Set FSO = Server.CreateObject("Scripting.FileSystemObject") For j = LBound(arrPath) to UBound(arrPath) - 1 winPath2 = winPath2 & arrPath(j) & "\" '判斷目的目錄是否存在,若不存在則建立 If not FSO.FolderExists(winPath1 & winPath2) Then FSO.CreateFolder(winPath1 & winPath2) End If Next Set FSO = Nothing '3、將遠端檔案下載到本地 Set objAdostream = Server.Createobject("ADODB.Stream") objAdostream.Open() objAdostream.Type = 1 objAdostream.Write(RemoteFile) objAdostream.SaveToFile(winPath1 & winPath2 & FileName), 2 '2 代表不詢問,直接覆蓋 objAdostream.SetEOS Set objAdostream = Nothing Response.Write "<font color=0000FF>第 " & i + 1 & " 筆:成功" & "<br>" '記錄成功的筆數 Total = Total + 1 'winPath 必須清除內容,不然會出現建立目錄時產生無限迴圈 winPath2 = "" End If Response.Flush Response.Clear Next Response.Write "<br><br>" Response.Write "<font color=0000FF>總相片數應為:</font>" & UBound(arrUrl, 1) & "<br>" Response.Write "<font color=0000FF>實際下載數為:</font>" & Total & "<br>" Response.Write "<font color=0000FF>未下載的連結:</font>" & "<br>" & ErrText & "<br>" %> |
資料來源:
如何用 asp 下載網址有中文字的遠端檔案
http://www.blueshop.com.tw/board/FUM200410061525290EW/BRD20140715120104M6P.html
本站其他相關資料 :
抓取遠端網頁錯誤代碼404,檢查遠端檔案是否存在
http://gdlion.blogspot.tw/2015/02/httpwebrequest404.html
2015年2月23日 星期一
抓取遠端網頁錯誤代碼404,檢查遠端檔案是否存在
<% Function postFormData(url, data) Dim xhr : Set xhr = Server.CreateObject("MSXML2.ServerXMLHTTP.3.0") xhr.open "POST", url, false xhr.setRequestHeader "Content-Type", "application/x-www-form-urlencoded" xhr.send Data postFormData=xhr.Status '錯誤代碼 '自訂錯誤內容 ' If (xhr.Status = 200) then ' postFormData = xhr.ResponseText ' ElseIf (xhr.Status = 404) then ' postFormData = xhr.ResponseText ' Else ' Err.Raise 1001, "postFormData", "Post to " & url & " failed with " & xhr.Status ' End If set xhr = Nothing End Function %> <% '如果A電腦沒有檔案,抓取B電腦的 url="http://100.100.100.111/big5/gencaa/upload/" & Rs("FilePath") if postFormData(url,"") = 404 then mail.AddAttachment "http://100.100.100.222/big5/gencaa/upload/" & Rs("FilePath") else mail.AddAttachment "http://100.100.100.111/big5/gencaa/upload/" & Rs("FilePath") end if %> |
本站其他相關資料:
- 抓取"檢視原始檔"內容。如何使用C#抓取網頁"真正"的本文http://gdlion.blogspot.tw/2013/10/c.html
- asp下載遠端檔案的程式碼
http://gdlion.blogspot.tw/2015/02/asp_24.html
其他:
httpwebrequest在 asp 的運用
2015年2月15日 星期日
asp執行dos指令,複製檔案
dim WShShell,fs,f Set WShShell = Server.CreateObject("WScript.Shell") set fs=Server.CreateObject("Scripting.FileSystemObject") set f=fs.CreateTextFile(Server.Mappath("C.bat"),true) 'f.write("copy " & Server.Mappath("aa.txt") & " " & Server.Mappath("bb.txt") & " /Y") f.write("copy D:\WebSite\aa.txt D:\WebSite\bb.txt /Y") f.close WShShell.Run Server.Mappath("C.bat"), 1, True set f=nothing set fs=nothing set WShShell=nothing |
2015年2月8日 星期日
檔案與資料夾,建立、刪除
Set fs=Server.CreateObject("Scripting.FileSystemObject")
'來源檔案存在 ---開始---
if fs.FileExists(Src_fName) then
'建立目的資料夾,如果沒有此資料夾,則建立資料夾。
ary_folder = Split(fPath,"\")
Des_fPath = "D:\APfileBK"
Des_fName = Des_fPath & "\" & fName
For i = 0 to UBound(ary_folder)-1
Des_fPath = Des_fPath & "\" & ary_folder(i)
IF not fs.FolderExists(Des_fPath) then
'Response.Write("<br>Des_fPath : " & Des_fPath)
fs.CreateFolder(Des_fPath)
End if
Next
'刪除 '@20141015 檔案有存在,先刪除
if fs.FileExists(Des_fName) then
'response.write("<br>Des_fName File exists! " & Des_fName)
'Flag(true or false):預設值為false,true表可以刪除唯讀屬性 設定的檔案,若不設為 true,則遇到唯讀屬性檔案時將產 生『沒有使用權限』的錯誤 (err.number=70)
fileOpen.close '關閉檔
fs.Deletefile Des_fName,true '刪除檔案 先關閉,才能刪除
end if
'搬移
fs.CopyFile Src_fName,Des_fPath & "\" ,true 'overwrite(是否覆蓋):預設值為true
#####################################################
#T=============================
#T=FSO相關操作
#T= 判斷目錄是否存在
<%
Function IsFloderExist(strFolderName)
SET FSO=Server.CreateObject("Scripting.FileSystemObject")
IF(FSO.FolderExists(strFolderName))THEN
IsFloderExist = True
ELSE
IsFloderExist = False
END IF
SET FSO=NOTHING
End Function
%>
#T= 創建目錄
<%
Function CreateFolder(strFolderName)
SET FSO=Server.CreateObject("Scripting.FileSystemObject")
IF(FSO.FolderExists(strFolderName) = False)THEN
FSO.CreateFolder(strFolderName)
END IF
SET FSO=NOTHING
END Function
%>
#T= 刪除目錄
<%
Function DeleteFolder(strFolderName)
SET FSO=Server.CreateObject("Scripting.FileSystemObject")
IF(FSO.FolderExists(strFolderName))THEN
FSO.DeleteFolder(strFolderName)
END IF
SET FSO=NOTHING
END Function
%>
#T= 判斷文件是否存在
<%
Function IsFileExist(strFileName)
SET FSO=Server.CreateObject("Scripting.FileSystemObject")
IF(FSO.FileExists(strFileName))THEN
IsFileExist = True
ELSE
IsFileExist = False
END IF
SET FSO=NOTHING
End Function
%>
#T= 刪除文件
<%
Function DeleteFile(strFileName)
SET FSO=Server.CreateObject("Scripting.FileSystemObject")
IF(FSO.FileExists(strFileName))THEN
FSO.DeleteFile(strFileName)
END IF
SET FSO=NOTHING
END Function
%>
2014年12月8日 星期一
asp建立utf-8文字檔
<% text = "good" call create_utf8(text) %> <% Sub create_utf8(text) const adTypeBinary = 1 const adSaveCreateOverwrite = 2 const adModeReadWrite = 3 Set objStream = server.CreateObject("ADODB.Stream") objStream.Open objStream.CharSet = "UTF-8" 'objStream.WriteText("your text goes here") objStream.WriteText(text) objStream.SaveToFile server.mappath(".") & "/fname.txt" , adSaveCreateOverWrite objStream.Close End Sub %> |
完畢。
來源 : 這篇
http://gchandra.wordpress.com/2004/08/19/creating-utf-8-files-using-asp/
用javascript語法寫
Thank’s for this tip.
Here is hte translated version for JScript:
var adTypeBinary = 1; var adSaveCreateOverWrite = 2; var adModeReadWrite = 3; var objStream = new ActiveXObject(“ADODB.Stream”); objStream.Open(); objStream.CharSet = “UTF-8〃; objStream.WriteText(content); objStream.SaveToFile(filename, adSaveCreateOverWrite); objStream.Close(); objStream.LoadFromFile filename objStream.ReadText |
if file exists to append data
補充:
Saving FileSystemObject as UTF
(來源:http://stackoverflow.com/questions/2907466/saving-filesystemobject-as-utf)
Dim objStream Set objStream = Server.CreateObject("ADODB.Stream") objStream.Type = adTypeText objStream.Mode = adModeReadWrite objStream.Open objStream.Position = 0 objStream.Charset = "UTF-8" objStream.WriteText strContent objStream.SaveToFile strABSPath,adSaveCreateOverWrite objStream.Close Set objStream=nothing |
2014年12月2日 星期二
字串補零 小技巧
例如抓月份和日期的時候,就不需要用if 來判斷比10小,前頭補零,
直接用right 來補零,簡單明瞭。
r_from_year+1911& right("00"&r_from_month,2) &right("00"&r_from_day,2)
2014年10月6日 星期一
設定網頁編碼
在做檔案複製的時候,發現中文檔名response出來變亂碼,調整網頁編碼utf-8時,中文檔名顯示正常,但iis給的中文錯誤訊息變亂碼。
因此設定網頁編碼
<head>
<meta http-equiv="Content-Type" content="text/html; charset=big5">
2014年8月18日 星期一
sql injection
<% Response.ExpiresAbsolute = Now() - 1 Response.Buffer = True Response.Expires = 0 Response.cacheControl="no cache" Function FRequest(ByVal ChkStr) Dim Str Str = Trim(Request(ChkStr)) If IsNull(Str) Then FRequest = "" Exit Function End If Dim re Set re = new RegExp re.IgnoreCase = True re.Global = True re.Pattern = "(\r\n){3,}" Str = re.Replace(Str,"$1$1$1") Set re = Nothing Str = Replace(Str,"'","''") Str = Replace(Str, "--", "--") Str = Replace(Str, "/*", "/*") Str = Replace(Str, "*/", "*/") Str = Replace(Str, "select", "select") Str = Replace(Str, "join", "join") Str = Replace(Str, "union", "union") Str = Replace(Str, "where", "where") Str = Replace(Str, "insert", "insert") Str = Replace(Str, "delete", "delete") Str = Replace(Str, "update", "update") Str = Replace(Str, "like", "like") Str = Replace(Str, "drop", "drop") Str = Replace(Str, "create", "create") Str = Replace(Str, "modify", "modify") Str = Replace(Str, "rename", "rename") Str = Replace(Str, "alter", "alter") Str = Replace(Str, "cast", "cast") Str = Replace(Str, "ASPSESSIONIDCCDDTASQ", "") Str = Replace(Str, "ASPSESSIONIDCACATBSQ", "") FRequest = Str End Function on error resume next %> <!-- #include file="../admin/setting/conn.asp"--> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html lang="zh-TW"> <head> |
程式 : cat, pda ,timesheet01.asp
2014年8月14日 星期四
檔案複製 錯誤 '800a0046' 沒有使用權限
Set fs=Server.CreateObject("Scripting.FileSystemObject")
fs.CopyFile Src_fName,Des_fPath & "\"
Microsoft VBScript 執行階段錯誤 錯誤 '800a0046' 沒有使用權限 /admin/big5/fun/gen/trans.asp, 列53 |
使用 On filesystemobject的 .filecopy 方法,得到以下錯誤訊息,應該如何處理?
Microsoft VBScript runtime error '800a0046'
Permission denied
答: 請確定最後的參數有包含一個反斜線(backslash) ,說明如下
是 "c:\temp\"
而不是 c:\temp"
參考
http://big5.webasp.net/article/13/12027.htm
遇到另一個狀況,也是出現同樣的錯誤訊息。
狀況 : 有修改過windows使用者密碼
重開機之後就正常了。
檔案名稱太複雜也不允許,例:RR-ENR-2.1-en-TW.pdf 。
2014年7月16日 星期三
搞定asp
搞定asp
這篇文章教你在一個小時裏如何搞定asp,非常實用,對於想學asp的同學可能有所幫助!!
一、語法
<1>語句
<%...........%>
<2>定義變數dim語句
<%
dim a,b
a=10
b=”ok!”
%>
注意:定義的變數可以是數值型,也可以是字元或者其他類型的
<3>簡單的控制流程語句
1. if 條件1 then
語句1
elseif 條件2 then
語句2
else
語句3
end if
2.while 條件
語句
wend
3.for count=1 to n step m
語句1
exit for
語句2
next
二.asp資料庫簡單*作教程
<1>.資料庫連接(用來單獨編制連接檔conn.asp)
<%
set conn = server.createobject(adodb.connection)
conn.open driver={microsoft access driver (*.mdb)}; dbq= & server.mappath(\bbs\db1\user.mdb)
%>
(用來連接bbs\db1\目錄下的user.mdb資料庫)
<2>顯示資料庫記錄
原理:將資料庫中的記錄一一顯示到用戶端流覽器,依次讀出資料庫中的每一條記錄
如果是從頭到尾:用迴圈並判斷指針是否到末 使用: not rs.eof
如果是從尾到頭:用迴圈並判斷指針是否到開始 使用:not rs.bof
(包含conn.asp用來打開bbs\db1\目錄下的user.mdb資料庫)
<%
set rs=server.createobject(adodb.recordset) (建立recordset物件)
sqlstr=select * from message ---->(message為資料庫中的一個資料表,即你要顯示的資料所存放的資料表)
rs.open sqlstr,conn,1,3 ---->(表示打開資料庫的方式)
rs.movefirst ---->(將指標移到第一條記錄)
while not rs.eof ---->(判斷指針是否到末尾)
response.write(rs(name)) ---->(顯示資料表message中的name欄位)
rs.movenext ---->(將指標移動到下一條記錄)
wend ---->(迴圈結束)
rs.close
conn.close 這幾句是用來關閉資料庫
set rs=nothing
set conn=nothing
%>
其中response對象是<a rel="nofollow" target="_blank" href='http://school.enet.com.cn/eschool/includes/zhuanti/shuyu/info/1/02/1684.shtml' target='
>增加資料庫記錄
增加資料庫記錄用到rs.addnew,rs.update兩個函數
(包含conn.asp用來打開bbs\db1\目錄下的user.mdb資料庫)
<%
set rs=server.createobject(adodb.recordset) (建立recordset物件)
sqlstr=select * from message ---->(message為資料庫中的一個資料表,即你要顯示的資料所存放的資料表)
rs.open sqlstr,conn,1,3 ---->(表示打開資料庫的方式)
rs.addnew 新增加一條記錄
rs(name)=xx 將xx的值傳給name欄位
rs.update 刷新資料庫
rs.close
conn.close 這幾句是用來關閉資料庫
set rs=nothing
set conn=nothing
%>
<4>刪除一條記錄
刪除資料庫記錄主要用到rs.delete,rs.update
(包含conn.asp用來打開bbs\db1\目錄下的user.mdb資料庫)
<%
dim name
name=xx
set rs=server.createobject(adodb.recordset) (建立recordset物件)
sqlstr=select * from message ---->(message為資料庫中的一個資料表,即你要顯示的資料所存放的資料表)
rs.open sqlstr,conn,1,3 ---->(表示打開資料庫的方式)
while not rs.eof
if rs.(name)=name then
rs.delete
rs.update 查詢資料表中的name欄位的值是否等於變數name的值xx,如果符合就執行刪除,
else 否則繼續查詢,直到指針到末尾為止
rs.movenext
emd if
wend
rs.close
conn.close 這幾句是用來關閉資料庫
set rs=nothing
set conn=nothing
%>
<5>關於資料庫的查詢
(a) 查詢欄位為字元型
<%
dim user,pass,qq,mail,message
user=request.form(user)
pass=request.form(pass)
qq=request.form(qq)
mail=request.form(mail)
message=request.form(message)
if trim(user)&x=x or trim(pass)&x=x then (檢測user值和pass值是否為空,可以檢測到空格)
response.write(註冊資訊不能為空)
else
set rs=server.createobject(adodb.recordset)
sqlstr=select * from user where user='&user&' (查詢user資料表中的user欄位其中user欄位為字元型)
rs.open sqlstr,conn,1,3
if rs.eof then
rs.addnew
rs(user)=user
rs(pass)=pass
rs(qq)=qq
rs(mail)=mail
rs(message)=message
rs.update
rs.close
conn.close
set rs=nothing
set conn=nothing
response.write(註冊成功)
end if
rs.close
conn.close
set rs=nothing
set conn=nothing
response.write(註冊重名)
%>
(b)查詢欄位為數字型
<%
dim num
num=request.form(num)
set rs=server.createobject(adodb.recordset)
sqlstr=select * from message where id=&num (查詢message資料表中id欄位的值是否與num相等,其中id為數字型)
rs.open sqlstr,conn,1,3
if not rs.eof then
rs.delete
rs.update
rs.close
conn.close
set rs=nothing
set conn=nothing
response.write(刪除成功)
end if
rs.close
conn.close
set rs=nothing
set conn=nothing
response.write(刪除失敗)
%>
<6>幾個簡單的asp物件的講解
response物件:伺服器端向用戶端發送的資訊物件,包括直接發送資訊給流覽器,重新定向url,或設置cookie值
request對象:用戶端向伺服器提出的請求
session物件:作為一個總體變數,在整個站點都生效
server物件:提供對伺服器上方法和屬性的訪問
(a) response物件的一般使用方法
比如:
<%
resposne.write(hello, welcome to asp!)
%>
在用戶端流覽器就會看到 hello, welcome to asp! 這一段文字
<%
response.redirect(www.sohu.com)
%>
如果執行這一段,則流覽器就會自動連接到 “搜狐” 的網址
關於response物件的用法還有很多,大家可以研究研究
request物件的一般使用方法
比如用戶端向伺服器提出的請求就是通過request物件來傳遞的列如 :你在申請郵箱的所填寫的個人資訊就是通過該物件來將你所填寫的資訊傳遞給伺服器的
比如:這是一段表單的代碼,這是提供給客戶填寫資訊的,填寫完了按“提交”傳遞給request.asp檔處理後再存入伺服器資料庫
<form target="_blank" name="form1" method="post">
<p>
<input type="text" name="user">
</p>
<p>
<input type="text" name="pass">
</p>
<p>
<input type="submit" name="submit" value="提交">
</p>
</form>
那麼request.asp該如何將其中的資訊讀入,在寫入資料庫,在這裏就要用到
request物件了,下面我們就來分析request.asp的寫法
<%
dim name,password (定義user和password兩個變數)
name=request.form(“user”) (將表單中的user資訊傳給變數name)
password=request.form(“pass”) (將表單中的pass資訊傳給變數password)
%>
通過以上的幾句代碼我們就將表單中的資料讀進來了,接下來我們要做的就是將
資訊寫入資料庫了,寫入資料庫的方法上面都介紹了,這裏就不一一復述了。
原文出處:http://smilealin.pixnet.net/blog/post/27721174-%E6%90%9E%E5%AE%9Aasp
這篇文章教你在一個小時裏如何搞定asp,非常實用,對於想學asp的同學可能有所幫助!!
一、語法
<1>語句
<%...........%>
<2>定義變數dim語句
<%
dim a,b
a=10
b=”ok!”
%>
注意:定義的變數可以是數值型,也可以是字元或者其他類型的
<3>簡單的控制流程語句
1. if 條件1 then
語句1
elseif 條件2 then
語句2
else
語句3
end if
2.while 條件
語句
wend
3.for count=1 to n step m
語句1
exit for
語句2
next
二.asp資料庫簡單*作教程
<1>.資料庫連接(用來單獨編制連接檔conn.asp)
<%
set conn = server.createobject(adodb.connection)
conn.open driver={microsoft access driver (*.mdb)}; dbq= & server.mappath(\bbs\db1\user.mdb)
%>
(用來連接bbs\db1\目錄下的user.mdb資料庫)
<2>顯示資料庫記錄
原理:將資料庫中的記錄一一顯示到用戶端流覽器,依次讀出資料庫中的每一條記錄
如果是從頭到尾:用迴圈並判斷指針是否到末 使用: not rs.eof
如果是從尾到頭:用迴圈並判斷指針是否到開始 使用:not rs.bof
(包含conn.asp用來打開bbs\db1\目錄下的user.mdb資料庫)
<%
set rs=server.createobject(adodb.recordset) (建立recordset物件)
sqlstr=select * from message ---->(message為資料庫中的一個資料表,即你要顯示的資料所存放的資料表)
rs.open sqlstr,conn,1,3 ---->(表示打開資料庫的方式)
rs.movefirst ---->(將指標移到第一條記錄)
while not rs.eof ---->(判斷指針是否到末尾)
response.write(rs(name)) ---->(顯示資料表message中的name欄位)
rs.movenext ---->(將指標移動到下一條記錄)
wend ---->(迴圈結束)
rs.close
conn.close 這幾句是用來關閉資料庫
set rs=nothing
set conn=nothing
%>
其中response對象是<a rel="nofollow" target="_blank" href='http://school.enet.com.cn/eschool/includes/zhuanti/shuyu/info/1/02/1684.shtml' target='
>增加資料庫記錄
增加資料庫記錄用到rs.addnew,rs.update兩個函數
(包含conn.asp用來打開bbs\db1\目錄下的user.mdb資料庫)
<%
set rs=server.createobject(adodb.recordset) (建立recordset物件)
sqlstr=select * from message ---->(message為資料庫中的一個資料表,即你要顯示的資料所存放的資料表)
rs.open sqlstr,conn,1,3 ---->(表示打開資料庫的方式)
rs.addnew 新增加一條記錄
rs(name)=xx 將xx的值傳給name欄位
rs.update 刷新資料庫
rs.close
conn.close 這幾句是用來關閉資料庫
set rs=nothing
set conn=nothing
%>
<4>刪除一條記錄
刪除資料庫記錄主要用到rs.delete,rs.update
(包含conn.asp用來打開bbs\db1\目錄下的user.mdb資料庫)
<%
dim name
name=xx
set rs=server.createobject(adodb.recordset) (建立recordset物件)
sqlstr=select * from message ---->(message為資料庫中的一個資料表,即你要顯示的資料所存放的資料表)
rs.open sqlstr,conn,1,3 ---->(表示打開資料庫的方式)
while not rs.eof
if rs.(name)=name then
rs.delete
rs.update 查詢資料表中的name欄位的值是否等於變數name的值xx,如果符合就執行刪除,
else 否則繼續查詢,直到指針到末尾為止
rs.movenext
emd if
wend
rs.close
conn.close 這幾句是用來關閉資料庫
set rs=nothing
set conn=nothing
%>
<5>關於資料庫的查詢
(a) 查詢欄位為字元型
<%
dim user,pass,qq,mail,message
user=request.form(user)
pass=request.form(pass)
qq=request.form(qq)
mail=request.form(mail)
message=request.form(message)
if trim(user)&x=x or trim(pass)&x=x then (檢測user值和pass值是否為空,可以檢測到空格)
response.write(註冊資訊不能為空)
else
set rs=server.createobject(adodb.recordset)
sqlstr=select * from user where user='&user&' (查詢user資料表中的user欄位其中user欄位為字元型)
rs.open sqlstr,conn,1,3
if rs.eof then
rs.addnew
rs(user)=user
rs(pass)=pass
rs(qq)=qq
rs(mail)=mail
rs(message)=message
rs.update
rs.close
conn.close
set rs=nothing
set conn=nothing
response.write(註冊成功)
end if
rs.close
conn.close
set rs=nothing
set conn=nothing
response.write(註冊重名)
%>
(b)查詢欄位為數字型
<%
dim num
num=request.form(num)
set rs=server.createobject(adodb.recordset)
sqlstr=select * from message where id=&num (查詢message資料表中id欄位的值是否與num相等,其中id為數字型)
rs.open sqlstr,conn,1,3
if not rs.eof then
rs.delete
rs.update
rs.close
conn.close
set rs=nothing
set conn=nothing
response.write(刪除成功)
end if
rs.close
conn.close
set rs=nothing
set conn=nothing
response.write(刪除失敗)
%>
<6>幾個簡單的asp物件的講解
response物件:伺服器端向用戶端發送的資訊物件,包括直接發送資訊給流覽器,重新定向url,或設置cookie值
request對象:用戶端向伺服器提出的請求
session物件:作為一個總體變數,在整個站點都生效
server物件:提供對伺服器上方法和屬性的訪問
(a) response物件的一般使用方法
比如:
<%
resposne.write(hello, welcome to asp!)
%>
在用戶端流覽器就會看到 hello, welcome to asp! 這一段文字
<%
response.redirect(www.sohu.com)
%>
如果執行這一段,則流覽器就會自動連接到 “搜狐” 的網址
關於response物件的用法還有很多,大家可以研究研究
request物件的一般使用方法
比如用戶端向伺服器提出的請求就是通過request物件來傳遞的列如 :你在申請郵箱的所填寫的個人資訊就是通過該物件來將你所填寫的資訊傳遞給伺服器的
比如:這是一段表單的代碼,這是提供給客戶填寫資訊的,填寫完了按“提交”傳遞給request.asp檔處理後再存入伺服器資料庫
<form target="_blank" name="form1" method="post">
<p>
<input type="text" name="user">
</p>
<p>
<input type="text" name="pass">
</p>
<p>
<input type="submit" name="submit" value="提交">
</p>
</form>
那麼request.asp該如何將其中的資訊讀入,在寫入資料庫,在這裏就要用到
request物件了,下面我們就來分析request.asp的寫法
<%
dim name,password (定義user和password兩個變數)
name=request.form(“user”) (將表單中的user資訊傳給變數name)
password=request.form(“pass”) (將表單中的pass資訊傳給變數password)
%>
通過以上的幾句代碼我們就將表單中的資料讀進來了,接下來我們要做的就是將
資訊寫入資料庫了,寫入資料庫的方法上面都介紹了,這裏就不一一復述了。
原文出處:http://smilealin.pixnet.net/blog/post/27721174-%E6%90%9E%E5%AE%9Aasp
訂閱:
文章 (Atom)