Sign in with Microsoft
Sign in or create an account.
Hello,
Select a different account.
You have multiple accounts
Choose the account you want to sign in with.

如需本文的 Microsoft FrontPage 2002 版本,請參閱
321439

如需本文的 Microsoft FrontPage 2000 版本,請參閱
321503

本文內容

結論

本文將逐步告訴您,如何藉由使用 FrontPage 2003、動態伺服器網頁 (ASP) 和 Microsoft Access 資料庫建立密碼保護的簡單網頁解決方案。

重要

  • 本文中的範例程式碼並非針對替代 FrontPage 2003 內建的安全性功能而設計。這些範例的目的是只針對瀏覽網站的使用者提供簡單的安全性機制。因此,FrontPage 2003 安全性並未與加入 Microsoft Access 資料庫的使用者名稱和密碼整合。

  • 輸入的使用者名稱和密碼會以純文字格式在網際網路上傳輸。為了提升安全性,Microsoft 建議您使用可利用 Secure Sockets Layer (SSL) 加密的網頁伺服器。如需詳細資訊,請聯絡網站管理員或網際網路服務提供者 (ISP)。

回到頁首

在 FrontPage 2003 中使用 ASP 功能

在使用 FrontPage 2003 中的 ASP 功能之前,您必須能夠存取支援 ASP 的 Web 伺服器或磁碟網站。


回到頁首

在 FrontPage 2003 中建立新網站

注意 範例資訊假設您為網站登入提供名稱,且您將該網站建立為網站根目錄以外的子網頁。如果您使用登入名稱以外的名稱,或者在不同的位置建立網站,就必須依其修改本文所有的步驟。

如果要在 FrontPage 2003 中建立新網站,請依照下列步驟執行:

  1. 啟動 FrontPage 2003。

  2. [檔案] 功能表上,按一下
    [新增]

  3. 在工作窗格中,按一下 [其他網站範本],然後按一下
    [空網站]

  4. [選項] 之下,以下列格式輸入要儲存新網站的位置:

    http://servername/logon其中 servername 是具備 ASP 功能的 Web 伺服器名稱。

  5. 按一下 [確定]

命名為登入名稱的新的空網站會在 FrontPage 2003 中開啟。

回到頁首

建立資料庫

使用資料庫程式 (例如 Microsoft Office Access 2003),來建立資料庫以儲存使用者名稱和密碼。

注意 如果使用 Access 2003 以外的程式建立資料庫,請修改以下步驟。

如果要建立資料庫,請依照下列步驟執行:

  1. 啟動 Access 2003。

  2. [檔案] 功能表上,按一下
    [新增]

  3. 在工作窗格中,按一下 [空白資料庫]

  4. 輸入 logon.mdb 做為檔案名稱,然後按一下
    [建立]

  5. [物件] 窗格中,按一下
    [資料表],然後按一下 [新增]

  6. 按一下 [設計檢視],然後按一下
    [確定]

  7. [欄位名稱] 資料欄的第一個資料列中,輸入
    UID。

  8. 在對應的 [資料類型] 資料欄中,按一下
    [文字],然後按一下工具列上的 [主索引鍵] 按鈕 (會顯示為鑰匙符號)。

  9. [欄位名稱] 資料欄的第二個資料列中,輸入
    PWD,然後在 [資料類型] 資料欄的第二個資料列中按一下
    [文字]

  10. [檔案] 功能表上,按一下
    [儲存檔案]

  11. [資料表名稱] 方塊中,輸入
    tblUsers,然後按一下 [確定]

  12. [檢視] 功能表上,按一下
    [資料工作表檢視]

  13. [UID] 資料欄中輸入
    testuser。

    [PWD] 資料欄中輸入
    password。

  14. [檔案] 功能表上,按一下 [關閉],然後結束 Access 2003。

注意 為了安全性的因素,密碼限於使用大小寫字母和數字的混合。

回到頁首

匯入資料庫

將您建立的使用者名稱和密碼資料庫匯入 FrontPage 2003。如果要執行這項操作,請依照下列步驟執行:

  1. 在 FrontPage 2003 中開啟了登入網站時,按一下 [檔案] 功能表上的
    [匯入]

  2. 按一下 [新增檔案],找出並按一下您建立的
    [logon.mdb] 檔案。

    按一下 [開啟]

  3. 按一下 [修改],在 [在 Web 內的檔案位置]方塊中輸入 _private/logon.mdb,然後按一下
    [確定]

    注意 在檔案路徑的 private 之前有一個底線字元 (_)。

  4. 按一下 [確定] 匯入資料庫檔案。

  5. 如果接到提示要您為這個匯入的檔案建立資料庫連線,請按一下
    [否]

回到頁首

建立 ASP 網頁

您必須建立數個檔案,才能使用這個範例。首先,請建立網站的首頁、用於測試的「不安全」網頁和密碼保護網頁,以及登入網頁和登入 Include 檔案。

建立首頁

本網頁用來當做網站的預設網頁,包含您建立的非安全性網頁和密碼保護網頁的連結。如果要建立首頁,請依照下列步驟執行:

  1. 在 FrontPage 2003 中,按一下 [建立新的網頁]按鈕。

  2. 在文件視窗的頁尾區域,按一下 [程式碼] 以顯示程式碼檢視。

  3. 選取網頁中的所有 HTML 程式碼,然後加以移除。

  4. 將下列的 HTML 程式碼輸入或貼入網頁中。

    <% @language="vbscript" %>
    <html>
    <head><title>Home Page</title></head>
    <body>
    <h3>Home Page</h3>
    <p>You are logged on as:
    <%
    If Len(Session("UID")) = 0 Then
    Response.Write "<b>You are not logged on.</b>"
    Else
    Response.Write "<b>" & Session("UID") & "</b>"
    End If
    %>
    </p>
    <ul>

    <li><a href="passwordprotect.asp">Password-Protected Page</a></li>
    <li><a href="nonsecure.asp">Nonsecure Page</a></li>

    </ul>
    </body>
    </html>
  5. 用滑鼠右鍵按一下 [new_page_1.htm] 索引標籤,然後按一下
    [儲存]

    將網頁以 default.asp的名稱儲存在登入網站的根資料夾中。

  6. [檔案] 功能表上按一下 [關閉],關閉 default.asp 網頁。

回到頁首

建立非安全性的網頁

建立可供每個人檢視的一般 ASP 網頁。如果要建立非安全性的網頁,請依照下列步驟執行:

  1. 在 FrontPage 2003 中,按一下 [建立新的網頁]按鈕。

  2. 在文件視窗的頁尾區域,按一下 [程式碼] 以顯示程式碼檢視。

  3. 選取網頁中的所有 HTML 程式碼,然後加以移除。

  4. 將下列的 HTML 程式碼輸入或貼入網頁中。

    <% @language="vbscript" %>
    <html>
    <head><title>Nonsecure Page</title></head>
    <body>
    <h3>Nonsecure Page</h3>
    <p>You are logged on as:
    <%
    If Len(Session("UID")) = 0 Then
    Response.Write "<b>You are not logged on.</b>"
    Else
    Response.Write "<b>" & Session("UID") & "</b>"
    End If
    %>
    </p>
    <p><a href="default.asp">Back to default</a></p>
    </body>
    </html>
  5. 用滑鼠右鍵按一下 [new_page_1.htm] 索引標籤,然後按一下
    [儲存]

    將網頁以 default.asp的名稱儲存在登入網站的根資料夾中。

  6. [檔案] 功能表上按一下 [關閉],關閉 nonsecure.asp 網頁。

回到頁首

建立密碼保護的網頁

此步驟中建立的網頁與您先前建立的非安全性網頁相同,只是您還必須在頁面頂端附近新增下列各行程式碼:

<!--#include virtual="/logon/_private/logon.inc"-->

當您將此程式碼行加入 ASP 網頁時,該網頁會由您建立的 logon.inc 檔案進行密碼保護。如果要建立密碼保護的網頁,請依照下列步驟執行:

  1. 在 FrontPage 2003 中,按一下 [建立新的網頁]按鈕。

  2. 在文件視窗的頁尾區域,按一下 [程式碼] 以顯示程式碼檢視。

  3. 選取網頁中的所有 HTML 程式碼,然後加以移除。

  4. 將下列的 HTML 程式碼輸入或貼入網頁中。

    <% @language="vbscript" %>
    <!--#include virtual="/logon/_private/logon.inc"-->
    <html>
    <head><title>Password-Protected Page</title></head>
    <body>
    <h3>Password-Protected Page</h3>
    <p>You are logged on as:
    <%
    If Len(Session("UID")) = 0 Then
    Response.Write "<b>You are not logged on.</b>"
    Else
    Response.Write "<b>" & Session("UID") & "</b>"
    End If
    %>
    </p>
    <p><a href="default.asp">Back to default</a>
    </body>
    </html>
  5. 用滑鼠右鍵按一下 [new_page_1.htm] 索引標籤,然後按一下
    [儲存]

    將網頁以 passwordprotect.asp的名稱儲存在登入網站的根資料夾中。

  6. [檔案] 功能表上按一下 [關閉],關閉 passwordprotect.asp 網頁。

回到頁首

建立登入頁面

建立外觀與一般 Windows 登入對話方塊類似的登入頁面。嘗試存取密碼保護網頁的使用者會被傳送到這個頁面,以輸入其使用者名稱和密碼。如果要建立登入頁面,請依照下列步驟執行:

  1. 在 FrontPage 2003 中,按一下 [建立新的網頁]按鈕。

  2. 在文件視窗的頁尾區域,按一下 [程式碼] 以顯示程式碼檢視。

  3. 選取網頁中的所有 HTML 程式碼,然後加以移除。

  4. 將下列的 HTML 程式碼輸入或貼入網頁中。

    <% @language="vbscript" %>
    <!--#include virtual="/logon/_private/logon.inc"-->
    <%
    ' Was this page posted to?
    If UCase(Request.ServerVariables("HTTP_METHOD")) = "POST" Then
    ' If so, check the username/password that was entered.
    If ComparePassword(Request("UID"),Request("PWD")) Then
    ' If comparison was good, store the user name...
    Session("UID") = Request("UID")
    ' ...and redirect back to the original page.
    Response.Redirect Session("REFERRER")
    End If
    End If
    %>
    <html>
    <head><title>Logon Page</title>
    <style>
    body { font-family: arial, helvetica }
    table { background-color: #cccccc; font-size: 9pt; padding: 3px }
    td { color: #000000; background-color: #cccccc; border-width: 0px }
    th { color: #ffffff; background-color: #0000cc; border-width: 0px }
    </style>
    </head>
    <body bgcolor="#000000" text="#ffffff">
    <h3 align="center"> </h3>
    <div align="center"><center>
    <form action="<%=LOGON_PAGE%>" method="POST">
    <table border="2" cellpadding="2" cellspacing="2">
    <tr>
    <th colspan="4" align="left">Enter User Name and Password</th>
    </tr>
    <tr>
    <td> </td>
    <td colspan="2" align="left">Please type your user name and password.</td>
    <td> </td>
    </tr>
    <tr>
    <td> </td>
    <td align="left">Site</td>
    <td align="left"><%=Request.ServerVariables("SERVER_NAME")%>  </td>
    <td> </td>
    </tr>
    <tr>
    <td> </td>
    <td align="left">User Name</td>
    <td align="left"><input name="UID" type="text" size="20"></td>
    <td> </td>
    </tr>
    <tr>
    <td> </td>
    <td align="left">Password</td>
    <td align="left"><input name="PWD" type="password" size="20"></td>
    <td> </td>
    </tr>
    <tr>
    <td> </td>
    <td colspan="2" align="center"><input type="submit" value="LOGON"></td>
    <td> </td>
    </tr>
    </table>
    </form>
    </center></div>
    </body>
    </html>
  5. 用滑鼠右鍵按一下 [new_page_1.htm] 索引標籤,然後按一下
    [儲存]

    將網頁以 logon.asp的名稱儲存在登入網站的根資料夾中。

  6. [檔案] 功能表上按一下 [關閉],關閉 logon.asp 網頁。

回到頁首

建立登入 Include 檔案

Include 檔案會提供使用者名稱和密碼功能,而且密碼保護的網頁和登入網頁都會用到這個檔案。如果要建立登入 Include 檔案,請依照下列步驟執行:

  1. 在 FrontPage 2003 中,按一下 [建立新的網頁]按鈕。

  2. 在文件視窗的頁尾區域,按一下 [程式碼] 以顯示程式碼檢視。

  3. 選取網頁中的所有 HTML 程式碼,然後加以移除。

  4. 將下列的 HTML 程式碼輸入或貼入網頁中。

    <%
    ' Do not cache this page.
    Response.CacheControl = "no-cache"

    ' Define the name of the users table.
    Const USERS_TABLE = "tblUsers"
    ' Define the path to the logon page.
    Const LOGON_PAGE = "/logon/logon.asp"
    ' Define the path to the logon database.
    Const MDB_URL = "/logon/_private/logon.mdb"

    ' Check to see whether you have a current user name.
    If Len(Session("UID")) = 0 Then
    ' Are you currently on the logon page?
    If LCase(LOGON_PAGE) <> LCase(Request.ServerVariables("URL")) Then
    ' If not, set a session variable for the page that made the request...
    Session("REFERRER") = Request.ServerVariables("URL")
    ' ...and redirect to the logon page.
    Response.Redirect LOGON_PAGE
    End If
    End If

    ' This function checks for a username/password combination.
    Function ComparePassword(UID,PWD)
    ' Define your variables.
    Dim strSQL, objCN, objRS
    ' Set up your SQL string.
    strSQL = "SELECT * FROM " & USERS_TABLE & _
    " WHERE (UID='" & ParseText(UID) & _
    "' AND PWD='" & ParseText(PWD) & "');"
    ' Create a database connection object.
    Set objCN = Server.CreateObject("ADODB.Connection")
    ' Open the database connection object.
    objCN.Open "driver={Microsoft Access Driver (*.mdb)}; dbq=" & _
    Server.MapPath(MDB_URL) & "; uid=admin; pwd="
    ' Run the database query.
    Set objRS = objCN.Execute(strSQL)
    ' Set the status to true/false for the database lookup.
    ComparePassword = Not(objRS.EOF)
    ' Close your database objects.
    Set objRS = Nothing
    Set objCN = Nothing
    End Function

    ' This function restricts text to alpha-numeric data only.
    Function ParseText(TXT)
    Dim intPos, strText, intText
    For intPos = 1 TO Len(TXT)
    intText = Asc(Mid(TXT,intPos,1))
    If (intText > 47 And intText < 58) Or _
    (intText > 64 And intText < 91) Or _
    (intText > 96 And intText < 123) Then
    strText = strText & Mid(TXT,intPos,1)
    End if
    Next
    ParseText = strText
    End Function
    %>
  5. 用滑鼠右鍵按一下 [new_page_1.htm] 索引標籤,然後按一下
    [儲存]

    將網頁以 logon.inc的名稱儲存在登入網站的 _private 資料夾中。

  6. [檔案] 功能表上按一下 [關閉],關閉 logon.inc 檔案。

回到頁首

測試登入網站

如果要執行這項操作,請依照下列步驟執行:

  1. 在 FrontPage 2003 的 [資料夾清單] 窗格中,用滑鼠右鍵按一下
    Default.asp,然後按一下
    [在瀏覽器中預覽]

    網頁瀏覽器會載入範例首頁,並顯示您並未登入。

  2. 按一下 [非安全性的網頁] 連結。

    網頁載入並顯示您並未登入。按一下 [回到預設值] 連結,返回預設頁面。

  3. 按一下 [密碼保護網頁] 連結。

    logon.asp 網頁載入,而不是密碼保護網頁。

  4. [使用者名稱] 方塊中輸入
    testuser,在 [密碼] 方塊中輸入
    password,然後按一下 LOGON


    密碼保護網頁出現,顯示您是以 testuser 名稱登入。按一下 [回到預設值] 連結,返回預設頁面。首頁載入,顯示您是以 testuser 名稱登入。

  5. 按一下 [非安全性的網頁] 連結。

    網頁載入,顯示您是以 testuser 名稱登入。

回到頁首

自訂登入網站

您可以用下列方式,來自訂登入範例網站:

  • 新增使用者名稱和密碼:您可以開啟資料庫。如果要執行這項操作,請在 FrontPage 2003 中按兩下資料庫,然後新增使用者到 tblUsers 資料表。

  • 以密碼保護其他網頁:如果要以密碼保護網站中另一個網頁,您必須以 ASP 副檔名儲存檔案 (例如,Mypage.asp),然後將下列兩行新增到檔案頂端:

    <% @language="vbscript" %>
    <!--#include virtual="/logon/_private/logon.inc"-->

    第一行指定您所使用的指令碼語言是 Microsoft Visual Basic Scripting Edition (VBScript),第二行則包含稍早所建立的登入 Include 檔案的使用者名稱和密碼功能。

回到頁首

参考

如需有關如何整合動態伺服器網頁 (ASP) 與資料庫的詳細資訊,請按一下下面的文件編號,檢視「Microsoft 知識庫」中的文件:

299987如何使用資料庫和 ASP 工作階段來執行 ASP 安全性

300382 如何:從 ASP 網頁建立與資料庫的連線:連線字串範例

318287 What you need to use Active Server Pages (ASP) in FrontPage 2002

回到頁首

Need more help?

Want more options?

探索訂閱權益、瀏覽訓練課程、瞭解如何保護您的裝置等等。

社群可協助您詢問並回答問題、提供意見反應,以及聆聽來自具有豐富知識的專家意見。

Was this information helpful?

How satisfied are you with the translation quality?
What affected your experience?
By pressing submit, your feedback will be used to improve Microsoft products and services. Your IT admin will be able to collect this data. Privacy Statement.

Thank you for your feedback!

×