现在的位置: 首页 > 综合 > 正文

Active Server Page (ASP) 常見問題

2013年10月03日 ⁄ 综合 ⁄ 共 12929字 ⁄ 字号 评论关闭

       Active Server Page (ASP) 常見問題

【「Active Server Page」以下簡稱「ASP」】







問: 如何將認證使用者儲存到Session變數(New)
問: ServerVariables("LOGON_USER")傳回空值(New)
問: ServerVariables("Remote_Host")傳回IP而不是HostName(New)
問: CDO版本摘要介紹
問: 何謂ADSI
問: 何謂ADsPath?
問: 如何得到LDAP Root DS Entry
問: 如何偵測瀏覽器的屬性?
問: 如何善用Response.Buffer增進瀏覽速度?
問: 如何利用Meta Tag來增加文件屬性?
問: Server.TransferResponse.Redirect相異之處?
問: Server.Execute#include相異之處?
問: 要如何使用ASPError物件?
問: 要如何讓以asp程式讓Internet Explorer 瀏覽器不cache
問: 如何依據瀏覽器語言版本設定ASP locale ID ?
問: 如何使用ASP/ADO query ODBC DATASOURCE
問: 要如何使用 Active Server Pages 程式預防瀏覽器開啟檔案時只顯示為Frameset的一部份?
問:

如何使用ASP 製作模擬動態生長的表單(form) ?

問: 如何使用ASP利用ADO呼叫SQLstored procedure
問: 我的程式中是否能放入Option Explicit?
Option Explicit
Response.Expires = 0
問: 如何在ASP程式中設定session timeout的長短?
問: 如果使用者不接受cookie會發生何種狀況?
問: 要如何設定ASPcache
問: 當使用了Proxy Server的情況下,Webpage回傳一個"Object Moved"的錯誤,要如何修改
asp程式解決這個問題?
問: 什麼時候增加ASP script engine cache,可以幫助運行的效率?
問: 使用 On filesystemobject.filecopy 方法,得到以下錯誤訊息,應該如何處理?

Microsoft VBScript runtime error '800a0046'
Permission denied

問: 如何設計一個page可以對每個登入的使用者提示歡迎的祝賀語如下?

Welcome <NT Username>

問: 是否有可能去讀取以及解析在其他site的檔案而無須附加其他的元件?
問: access自己web site 下的virtual directory ,會發生以下的錯誤訊息,該如何處理?

HTTP/1.1 500 Server Error -2146646015 (0x800cc801)

問: 為何IISOnline文件的Index tab沒有包含所有的章節?
問: 為何無法在PWS 或是NT Workstation 版的IIS上做搜尋文件?
問: 為何當disable 自動密碼同步後,匿名使用者無法進入web site
問: ASP 1.0有哪幾個版本?
問: 發生以下的錯誤是什麼原因?

Microsoft VBScript compilation error '800a0414'
Cannot use parens when calling a Sub
/test/test.asp, line 17
myobj.movefile(fname, sfolder, tfolder)
---------------------------------------^

問: 要如何強迫 session 關閉?
問: 發生以下的錯誤是什麼原因,要如何解決?

error 'ASP 0115' Unexpected error
/disney/main.asp
A trappable error occurred in an external object. The script cannot continue running.

問: 為何會發生"HTTP Headers already written" 的錯誤?
問: 使用以Microsoft Visual C++ 寫的 server-side 元件如何除錯?
問: 當更新了在 wwwroot 目錄下的檔案,可是一定要重新啟動web server才能看到這些檔案被更新,是否由caching 所造成的問題?
問: Internet Information Server (IIS) 如何得知要將.asp 檔案傳遞到 Microsoft Active Server Pages (ASP)?
問: 為何會發生奇怪的錯誤當使用CreateObject 存取元件?
問: 要如何設定Microsoft Internet Information Server (IIS) 讓預設網頁為default.asp 檔案?
問: 當將一個.asp檔案放到web server上,當由瀏覽器讀取這個.asp檔案時卻可以看到整個.asp程式碼,有什麼不對呢?
問: 哪些作業系統支援執行ASP
問: 是否能夠從一支asp程式呼叫在另一支asp程式的副程式或函數?
問: 是否能夠從一支asp程式存取在另一支asp程式的變數?
問: VBScript 是否在Response.Redirect執行後執行?
問: VBScript 是否在Response.End執行後執行?
問: 什麼原因會產生錯誤訊息如下?
Response object error 'ASP 0156' Header Error
/intranet_devel/scripts/CheckLog.asp, line 14
The HTTP headers are already written to the client
browser. Any HTTP header modifications must be made before writing page content.
問: Session變數是否能使用在web farm?
問: 什麼原因會產生錯誤訊息如下?
'ASP 0113'The max amount of time for a script to execute was
exceed, you can change this limit by specifying a
new value for the property server. Script Time out
or by changing the value for Script Time out.
問: 什麼原因會產生錯誤訊息如下?
Microsoft OLE DB Provider for ODBC Drivers error '80004005'
[Microsoft][ODBC SQL Server Driver][dbnmpntw]ConnectionOpen (CreateFile()).
問: 什麼原因會產生錯誤訊息如下?
Server object error 'ASP 0177:80040112'
Server.CreateObject Failed [Filename], line [line number]
The call to Server.CreateObject failed. The requested object instance cannot be created.
問: 什麼原因會產生錯誤訊息如下?
Microsoft VBScript runtime error '800a000d'
Type mismatch
問: 什麼原因會產生錯誤訊息如下?
Error ASP 0115 unexpected error.
Trappable error occured in an external object, the script cannot continue running.
問: 什麼原因會產生錯誤訊息如下?
Server object error 'ASP 177:800401f3'Server.CreateObject Failed
/aspsamp/tutorial/lessons/Finance.asp, line 52
The call to Server.CreateObject failed. The requested object instance cannot be created.
問: 什麼原因會產生錯誤訊息如下?
Server object error 'ASP 0177:80040154 'Server.createobject failed
/advworks/equipment/equip.asp, line 2
The call to server.createobject failed The requeted object instance can not be created.
問: 由於cookie的生命週期僅發生在目前的IE session,如果結束IE並且重新啟動IE ,這時 cookie就消逝了,應如何控制cookie的使用期限?
問: 如何由client端得知螢幕解析度?








問: 如何將認證使用者儲存到Session變數(New)
答: <%
If Session("LOGON_USER") = "" Then
If Request.ServerVariables("LOGON_USER") = "" Then
  Response.Status = "401 Access Denied"
  Response.End
Else
  Session("LOGON_USER") = Request.ServerVariables("LOGON_USER")
  ' the following lines strip out an NT domain from the user name
  If InStr(Session("LOGON_USER"),"/") then
    Session("LOGON_USER") = Right(Session("LOGON_USER"), Len(Session("LOGON_USER")) - InStr(Session("LOGON_USER"),"/"))
  End If
End If
End If
%>
問: ServerVariables("LOGON_USER")傳回空值(New)
答: 如果ASP page使用"允許匿名存取",則"LOGON_USER"variable將會傳回空值。如果要正確顯示請將認證模式設為基本驗證或整合Windows驗證即可。
問: ServerVariables("Remote_Host")傳回IP而不是HostName(New)
答: 在預設情況下,ServerVariables("Remote_Host")傳回IP,這是設計上的考量,為了要增進IIS的效能,但您仍可藉由修改Metabase,叫IIS去跟DNS做查詢,詳細請見KB Q245574
問: CDO版本摘要介紹
答:
Library 來源 檔名 ProgID
CDO 1.0 Exchange 4.0 Mdlsp.dll
Mdlsp32.dll
MAPI
CDO 1.1 Exchange 5.0 OleMsg.dll
OleMsg32.dll
MAPI
CDO 1.2 Exchange 5.5
Outlook 98
Outlook 2000
Exchange 2000
Cdo.dll  MAPI
CDO for NTS 1.2 Exchange 5.5
IIS 4.0
MCIS
Windows 2000
CdoNTS.dll  CDONTS
CDO for Windows 2000 (CDO 2.0) Windows 2000 Cdosys.dll CDO
CDO for Exchange 2000 (CDO 3.0) Exchange 2000 Cdoex.dll CDO
CDO for Exchange Management 1.0 Exchange 2000 Cdoexm.dll CDOEXM
CDO WorkFlow Objects for Microsoft Exchange 1.0 Exchange 2000 Cdowf.dll CDOWF

問: 何謂ADSI
答: ADSI是一組存取不同目錄服務的介面,這裡將會專注在存取Windows 2000 Active Directory directory service. ADSI使用LDAP協定來跟Active Directory溝通。
問: 何謂ADsPath?
答: 當使用程式存取Active Directory時,你必須提供LDAP namespace(progID)和物件的路徑(ADsPath),以下是一些ADsPath的範例:
ADSI object ADsPath
Organizational unit in the nwtraders domain LDAP://OU=Sales, DC=nwtraders, DC=msft
Exchange object on Exchange Server LDAP://exch01/O=Microsoft
jsmith user in the Sales OU of the nwtraders domain LDAP://CN=jsmith, OU=Sales, DC=nwtraders, DC=msft
comp1 in the Redmond domain WinNT://REDMOND/comp1, computer
alice, a local user on the comp1 computer WinNT://REDMOND/comp1/alice

問: 如何得到LDAP Root DS Entry
答: RFC 2251 中規範所有的LDAP directory都必須擁有一個特別內容rootDSE object,其中一個標準的屬性叫做defaultNamingContext,在Windows 2000 中,他會回傳Active Directory根目錄的名稱,請見以下範例:
Set Root = GetObject("LDAP://RootDSE")
DomainPath = Root.Get("DefaultNamingContext")
Set Domain = GetObject("LDAP://"& DomainPath)
問: 如何偵測瀏覽器的屬性?
答: 利用MSWC.BrowserType可以偵測到瀏覽器許多屬性,如瀏覽器名稱、版本,是否支援cookies、frames、tables、BackGroundSounds、VBScript、JavaScript等。例如: Set bc = Server.CreateObject("MSWC.BrowserType")
if bc.cookies=True then...
問: 如何利用Response.Buffer增進瀏覽速度?
答: 利用Response.Buffer=True,Response.Flush可以增進使用者瀏覽速度,如果一個頁面 Response.Buffer=False,有30個資料傳輸,若有100個人瀏覽此頁面,則有 3000個來回傳輸,嚴重影響效率;若在起始處設定 Response.Buffer=True,再將整個頁面分為幾個群組,在設當的地方搭配 Response.Flush,則可大幅改善使用者經驗。
問: 如何利用Meta Tag來增加文件屬性?
答: Meta Tag 中記錄著各種要提供給瀏覽器的隱藏資訊或指示,如
<META NAME="Update" CONTENT="2000/9/7">
<META NAME="Author" CONTENT="Jerry">
<META NAME="KeyWords" CONTENT="ASP">
<META NAME="Description" CONTENT="VID/ASP FAQ">
如此可讓搜尋引擎或Web Crawler自動進行讀取。
問: Server.TransferResponse.Redirect相異之處?
答: 雖然Server.TransferResponse.Redirect都會轉向,但兩者之間仍有些不同:
Response.Redirect是先由伺服器端將資料送到用戶端,用戶端再依照Redirect內容,向伺服器端要求轉向到另一個網頁,如此會增加一次用戶端與伺服器端來回通訊時間,而Server.Transfer則是在伺服器端直接轉向到另一個網頁。並且由於Server.Transfer轉向前後的網頁,仍屬同一應用程式,因此會將SessionApplication的變數值帶到轉向後的URL位置,而Response.Redirect不會。
問: Server.Execute#include相異之處?
答: Execute Method 是呼叫一個.asp 檔案並執行它,比較類似一般程式語言的procedure call;而#include則僅將所包含的程式插入原程式當中。
問: 要如何使用ASPError物件?
答: 首先由Set objASPError=Server.GetLastError取得錯誤資訊,接著由ASPError物件的屬性取得相關訊息:
objASPError.ASPCode:傳回IIS產生的錯誤碼
objASPError.Number:傳回COM標準錯誤碼,如 0x800A03FC
objASPError.Source:傳回實際產生錯誤的原始碼
objASPError.Category:指出錯誤的來源為ASPScript或是Object
objASPError.File:傳回錯誤程式檔案名稱
objASPError.Line:傳回錯誤程式碼的行數
objASPError.Column:傳回錯誤程式碼的列數
objASPError.Description:傳回錯誤原因簡介
objASPError.ASPDescription:傳回詳細錯誤原因
問: 要如何讓以asp程式讓Internet Explorer 瀏覽器不cache
答: 除了由IIS可設定讓Internet Explorercache以外,可以用以下的asp script,基本上是使用HTTP header控制cache
以下
script必須執行在HTTP 1.1 server ,適用於Internet Explorer 4.0以上版本。

<% Response.CacheControl = "no-cache" %>
<% Response.AddHeader "Pragma", "no-cache" %>
<% Response.Expires = -1 %>

問: 如何依據瀏覽器語言版本設定ASP locale ID ?
答: 使用以下的副程式就是依據使用者的瀏覽器語言,動態設定ASP應用程式 Locale ID
(Session.LCID)

<SCRIPT Runat=Server Language=VBScript>
Sub SetLCID()
Dim strAcceptLanguage
Dim strLCID
Dim strPos

strAcceptLanguage = Request.ServerVariables("HTTP_ACCEPT_LANGUAGE")

strPos = InStr(1, strAcceptLanguage, ",")
If strPos > 0 Then
strAcceptLanguage = Left(strAcceptLanguage, strPos - 1)
End If

Select Case LCase(strAcceptLanguage)
Case "af"
strLCID = 1078 ' Afrikaans
Case "sq"
strLCID = 1052 ' Albanian
Case "ar-sa"
strLCID = 1025 ' Arabic(Saudi Arabia)
Case "ar-iq"
strLCID = 2049 ' Arabic(Iraq)
Case "ar-eg"
strLCID = 3073 ' Arabic(Egypt)
Case "ar-ly"
strLCID = 4097 ' Arabic(Libya)
Case "ar-dz"
strLCID = 5121 ' Arabic(Algeria)
Case "ar-ma"
strLCID = 6145 ' Arabic(Morocco)
Case "ar-tn"
strLCID = 7169 ' Arabic(Tunisia)
Case "ar-om"
strLCID = 8193 ' Arabic(Oman)
Case "ar-ye"
strLCID = 9217 ' Arabic(Yemen)
Case "ar-sy"
strLCID = 10241 ' Arabic(Syria)
Case "ar-jo"
strLCID = 11265 ' Arabic(Jordan)
Case "ar-lb"
strLCID = 12289 ' Arabic(Lebanon)
Case "ar-kw"
strLCID = 13313 ' Arabic(Kuwait)
Case "ar-ae"
strLCID = 14337 ' Arabic(U.A.E.)
Case "ar-bh"
strLCID = 15361 ' Arabic(Bahrain)
Case "ar-qa"
strLCID = 16385 ' Arabic(Qatar)
Case "eu"
strLCID = 1069 ' Basque
Case "bg"
strLCID = 1026 ' Bulgarian
Case "be"
strLCID = 1059 ' Belarusian
Case "ca"
strLCID = 1027 ' Catalan
Case "zh-tw"
strLCID = 1028 ' Chinese(Taiwan)
Case "zh-cn"
strLCID = 2052 ' Chinese(PRC)
Case "zh-hk"
strLCID = 3076 ' Chinese(Hong Kong)
Case "zh-sg"
strLCID = 4100 ' Chinese(Singapore)
Case "hr"
strLCID = 1050 ' Croatian
Case "cs"
strLCID = 1029 ' Czech
Case "da"
strLCID = 1030 ' Danish
Case "n"
strLCID = 1043 ' Dutch(Standard)
Case "nl-be"
strLCID = 2067 ' Dutch(Belgian)
Case "en"
strLCID = 9 ' English
Case "en-us"
strLCID = 1033 ' English(United States)
Case "en-gb"
strLCID = 2057 ' English(British)
Case "en-au"
strLCID = 3081 ' English(Australian)
Case "en-ca"
strLCID = 4105 ' English(Canadian)
Case "en-nz"
strLCID = 5129 ' English(New Zealand)
Case "en-ie"
strLCID = 6153 ' English(Ireland)
Case "en-za"
strLCID = 7177 ' English(South Africa)
Case "en-jm"
strLCID = 8201 ' English(Jamaica)
Case "en"
strLCID = 9225 ' English(Caribbean)
Case "en-bz"
strLCID = 10249 ' English(Belize)
Case "en-tt"
strLCID = 11273 ' English(Trinidad)
Case "et"
strLCID = 1061 ' Estonian
Case "fo"
strLCID = 1080 ' Faeroese
Case "fa"
strLCID = 1065 ' Farsi
Case "fi"
strLCID = 1035 ' Finnish
Case "fr"
strLCID = 1036 ' French(Standard)
Case "fr-be"
strLCID = 2060 ' French(Belgian)
Case "fr-ca"
strLCID = 3084 ' French(Canadian)
Case "fr-ch"
strLCID = 4108 ' French(Swiss)
Case "fr-lu"
strLCID = 5132 ' French(Luxembourg)
Case "gd"
strLCID = 1084 ' Gaelic(Scots)
Case "gd-ie"
strLCID = 2108 ' Gaelic(Irish)
Case "de"
strLCID = 1031 ' German(Standard)
Case "de-ch"
strLCID = 2055 ' German(Swiss)
Case "de-at"
strLCID = 3079 ' German(Austrian)
Case "de-lu"
strLCID = 4103 ' German(Luxembourg)
Case "de-li"
strLCID = 5127 ' German(Liechtenstein)
Case "e"
strLCID = 1032 ' Greek
Case "he"
strLCID = 1037 ' Hebrew
Case "hi"
strLCID = 1081 ' Hindi
Case "hu"
strLCID = 1038 ' Hungarian
Case "is"
strLCID = 1039 ' Icelandic
Case "in"
strLCID = 1057 ' Indonesian
Case "it"
strLCID = 1040 ' Italian(Standard)
Case "it-ch"
strLCID = 2064 ' Italian(Swiss)
Case "ja"
strLCID = 1041 ' Japanese
Case "ko"
strLCID = 1042 ' Korean
Case "ko"
strLCID = 2066 ' Korean(Johab)
Case "lv"
strLCID = 1062 ' Latvian
Case "lt"
strLCID = 1063 ' Lithuanian
Case "mk"
strLCID = 1071 ' Macedonian
Case "ms"
strLCID = 1086 ' Malaysian
Case "mt"
strLCID = 1082 ' Maltese
Case "no"
strLCID = 1044 ' Norwegian(Bokmal)
Case "no"
strLCID = 2068 ' Norwegian(Nynorsk)
Case "p"
strLCID = 1045 ' Polish
Case "pt-br"
strLCID = 1046 ' Portuguese(Brazilian)
Case "pt"
strLCID = 2070 ' Portuguese(Standard)
Case "rm"
strLCID = 1047 ' Rhaeto-Romanic
Case "ro"
strLCID = 1048 ' Romanian
Case "ro-mo"
strLCID = 2072 ' Romanian(Moldavia)
Case "ru"
strLCID = 1049 ' Russian
Case "ru-mo"
strLCID = 2073 ' Russian(Moldavia)
Case "sz"
strLCID = 1083 ' Sami(Lappish)
Case "sr"
strLCID = 3098 ' Serbian(Cyrillic)
Case "sr"
strLCID = 2074 ' Serbian(Latin)
Case "sk"
strLCID = 1051 ' Slovak
Case "s"
strLCID = 1060 ' Slovenian
Case "sb"
strLCID = 1070 ' Sorbian
Case "es"
strLCID = 1034 ' Spanish(Spain - Traditional Sort)
Case "es-mx"
strLCID = 2058 ' Spanish(Mexican)
Case "es"
strLCID = 3082 ' Spanish(Spain - Modern Sort)
Case "es-gt"
strLCID = 4106 ' Spanish(Guatemala)
Case "es-cr"
strLCID = 5130 ' Spanish(Costa Rica)
Case "es-pa"
strLCID = 6154 ' Spanish(Panama)
Case "es-do"
strLCID = 7178 ' Spanish(Dominican Republic)
Case "es-ve"
strLCID = 8202 ' Spanish(Venezuela)
Case "es-co"
strLCID = 9226 ' Spanish(Colombia)
Case "es-pe"
strLCID = 10250 ' Spanish(Peru)
Case "es-ar"
strLCID = 11274 ' Spanish(Argentina)
Case "es-ec"
strLCID = 12298 ' Spanish(Ecuador)
Case "es-c"
strLCID = 13322 ' Spanish(Chile)
Case "es-uy"
strLCID = 14346 ' Spanish(Uruguay)
Case "es-py"
strLCID = 15370 ' Spanish(Paraguay)
Case "es-bo"
strLCID = 16394 ' Spanish(Bolivia)
Case "es-sv"
strLCID = 17418 ' Spanish(El Salvador)
Case "es-hn"
strLCID = 18442 ' Spanish(Honduras)
Case "es-ni"
strLCID = 19466 ' Spanish(Nicaragua)
Case "es-pr"
strLCID = 20490 ' Spanish(Puerto Rico)
Case "sx"
strLCID = 1072 ' Sutu
Case "sv"
strLCID = 1053 ' Swedish
Case "sv-fi"
strLCID = 2077 ' Swedish(Finland)
Case "th"
strLCID = 1054 ' Thai
Case "ts"
strLCID = 1073 ' Tsonga
Case "tn"
strLCID = 1074 ' Tswana
Case "tr"
strLCID = 1055 ' Turkish
Case "uk"
strLCID = 1058 ' Ukrainian
Case "ur"
strLCID = 1056 ' Urdu
Case "ve"
strLCID = 1075 ' Venda
Case "vi"
strLCID = 1066 ' Vietnamese
Case "xh"
strLCID = 1076 ' Xhosa
Case "ji"
strLCID = 1085 ' Yiddish
Case "zu"
strLCID = 1077 ' Zulu
Case Else
strLCID = 2048 ' default
End Select

Session.LCID = strLCID
End Sub
</SCRIPT>

Sample ASP Page
---------------

以下的asp程式展示Locale 的變換,請在瀏覽器中的Internet 選項,改變語言設定。再refresh 這個 ASP page

NOTE: The SetLCID() 副程式請include在檔案setlcid.inc.

<%@ Language=VBScript %>
<HTML>
<BODY>

<!--#include file=setlcid.inc -->

<%
SetLCID 'Set the Locale ID per the browser

Response.Write "Date/Time Formats"
Response.Write "<p>Date = " & Date()
Response.Write "<br>Month = " & Month(Date())
Response.Write "<br>Day = " & Day(Date())
Response.Write "<br>Year = " & Year(Date())
Response.Write "<br>Time = " & Time()

Response.Write "<p>Currency Formats"
Response.Write "<p>" & FormatCurrency(1.05, 2)
Response.Write "<br>" & FormatNumber(1000000,2)
Response.Write "<br>" & FormatNumber(-1000000,2)

%>
</BODY>
</HTML>

問: 如何使用ASP/ADO query ODBC DATASOURCE
答: 以下的example僅做測試目的,測試 ADO 連接到任何 ODBC Datasource
<HTML>
<%
if Request("REQUESTTYPE") <> "POST" then
' %%%%%%%%%%%%%%%%%%%%%%%

抱歉!评论已关闭.