問: |
如何將認證使用者儲存到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.Transfer和Response.Redirect相異之處? |
答: |
雖然Server.Transfer和Response.Redirect都會轉向,但兩者之間仍有些不同: Response.Redirect是先由伺服器端將資料送到用戶端,用戶端再依照Redirect內容,向伺服器端要求轉向到另一個網頁,如此會增加一次用戶端與伺服器端來回通訊時間,而Server.Transfer則是在伺服器端直接轉向到另一個網頁。並且由於Server.Transfer轉向前後的網頁,仍屬同一應用程式,因此會將Session和Application的變數值帶到轉向後的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:指出錯誤的來源為ASP、Script或是Object objASPError.File:傳回錯誤程式檔案名稱 objASPError.Line:傳回錯誤程式碼的行數 objASPError.Column:傳回錯誤程式碼的列數 objASPError.Description:傳回錯誤原因簡介 objASPError.ASPDescription:傳回詳細錯誤原因 |
問: |
要如何讓以asp程式讓Internet Explorer 瀏覽器不cache? |
答: |
除了由IIS可設定讓Internet Explorer不cache以外,可以用以下的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 ' %%%%%%%%%%%%%%%%%%%%%%%
|