發佈日期: 2007 年 11 月 1 日
Publication date: 1 November 2007
作者: 王恩琦 (TechNet 技術論壇 WSS 版版主;微軟 2007 年度 WSS MVP)
http://blog.blueshop.com.tw/angi/
本頁內容
Stage 1. 建立 WSS 網站
Stage 2. 建立 FBA 資料庫與帳號
Stage 3. 修改 WSS web.config
Stage 4. 設定 WSS 網站的驗證模式
Stage 1. Create WSS website
Stage 2. Create FBA database and account
Stage 3. Modify WSS web web.config
Stage 4. Configure WS website authentication mode
WSS 的 Form 驗證,自 WSS 2.0 開始,就是一直被討論與期待的功能,據官方說法 WSS 2.0 架構是不支援 Form 驗證的,當然,還是有人在 WSS 2.0 版做出 Form 驗證的,真是佩服!
WSS's Form test, which has been discussed and expected since WS 2.0, is officially not supported by the WSS 2.0 structure. Of course, it's impressive that someone made the Form test on WS 2.0!
而這回微軟終於在 WSS 3.0 正式支援 Form 驗證的功能,其方法與流程也變得便捷許多,使得 WSS 網站能在 Internet 上公開不再是一件困難的事情了。
This time Microsoft officially supports the functions of Form at WS 3.0, and its methods and processes have become much easier, making it no longer difficult for the WS website to be publicly available on the Internet.
本文實作 Form 驗證之前,當然的,必須先擁有一個 WSS 3.0 網站,什麼?不知道 WSS 3.0 為何物?不知道怎麼安裝 WSS 3.0 網站?那煩請先換個地方,參考小弟 Blog 上的拙作【認識 SharePoint 2007 系列】的文章,安裝一下環境。下面,小弟先將整個 WSS 3.0 從安裝開始,到完成 Form 驗證的設定,分成四個階段,並用一個簡單的圖將每個階段的重點步驟點出,相信對接下來要進行的工作,能有比較清晰的輪廓:
Before the Form test, of course, there must be a WSS 3.0 site. Don't know what WSS 3.0 is. Don't know how to install the WSS 3.0 site. That bothers you to change places to look at the little brother Blog's coarse article on the SharePoint 2007 series and to install the environment. Below, the entire WSS 3.0 should be divided into four stages from the installation to the completion of the Form validation configuration, with a simple diagram that puts out the top points of each segment, believing that there is a clearer contours for the work to be done:
關於 WSS 網站的建立,本階段僅列出前置作業、安裝過程與安裝相關的連結提供參考,就不在此贅述安裝的過程了:
With regard to the creation of the WSS site, this section does not describe the installation process simply by listing the links between pre-production, installation and installation:
Step 1-1. 安裝前的準備
Step 1-1. Preparation for installation
Step 1-2. 安裝 WSS 3.0 與建立網站
Step 1-2. Install WS 3.0 and create websites
Step 1-3. 開啟匿名存取
Step 1-3. Enable anonymous access
要讓使用者從 Internet 等外部環境登入 WSS 網站,其方法是使用 Form 驗證 (forms-based authentication, FBA);FBA 的實作需要建立一個資料庫來儲存使用者的資訊,做為使用者登入網站驗證的基礎。而在此實作 FBA 的方法是使用 ASP.NET 2.0 與 SQL Server 整合的 Membership 與 Role Provider 機制,這種方法也是最快建置 FBA 的方法。
To allow users to enter the WSS site from outside the Internet, for example, by using the Form-base verification, FBA; the FBA implementation requires the creation of a database to store user information as the basis for the user to log in to the site validation. The FBA implementation here is by using the ASP.NET 2.0 and SQL Server integrated Membership and Rale Provider schemes, which are also the fastest way to build the FBA.
本階段您要完成下列三個步驟:
You will complete the following three steps in this session:
Step 2-1. 建立 FBA 資料庫
Step 2-1. Create a FBA database
Step 2-2. 設定 Membership 與 Provider
Step 2-2. Configure Membership and Provider
Step 2-3. 建立使用者帳號
Step 2-3. Create user accounts
Step 2-1. 建立 FBA 資料庫
打開 Windows 的【執行】,輸入【c:\windows\microsoft.net\framework\v2.0.50727\aspnet_regsql】將會啟動 ASP.NET SQL Server 安裝精靈。
Open Windows' [execution] and enter [c:\windows\microsoft.net\framework\v2.0.5072.aspnet_regsql] will activate ASSP.NET SQL Server to install elves.
安裝精靈畫面,點選【下一步】。
Install elf screens, click Next.
點選【設定應用程式服務的 SQL Server】。
Click [SQL Server for Configure Application Services].
在【伺服器】輸入您的伺服器名稱,使用【Windows 驗證】,資料庫則輸入【aspnetdb】,按【下一步】。
Enter your server name in [server], using [Windows Validation], while the database enters [aspnetdb], press [next].
確認設定畫面,如果輸入有誤,請按【上一步】去修改,如果沒有錯誤則點選【下一步】開始安裝。
Confirms the setting of the screen, and if the input is wrong, press [the previous step] to modify it and click [the next step] to install it if there is no error.
資料庫建立完成。
Database established.
Step 2-2. 設定 Provider
Step2-2. ConfigureProvider
當我們完成資料庫的建立後,使用者資訊、角色資訊當然是空的,所以我們至少要新增一個使用者來做登入的驗證,甚至指定為網站的管理者;由於剛剛建立的 aspnetdb 結構有些許複雜,一時很難瞭解 User、Role 等等之間的關係,所以我們使用 ASP .NET 的 Configuration 功能來快速建立一個帳號輸入介面,這個步驟又可分為幾個小步驟,在這邊先簡要說明一下流程:
When we complete the database, user information, role information is certainly empty, so at least one new user will be added to the login test, or even designated as site manager; given the complexity of the aspnetdb structure that has just been created, it is difficult to understand the relationship between User, Role, etc., so we use the ASP.NET function to quickly create an account input interface, a step that can be divided into a few small steps to describe the process:
先建立 ASP .NET Web Site 專案
Create ASP.NET WebSite project first
修改專案的 web.config 將資料庫指向 aspnetdb
Modify project web.config to point database to aspnetdb
在 web.config 建立新增 Membership 與 Provider
Create new Web.config Membership and Provider
使用 ASP.NET Configuration 產生輸入介面
Generate an input interface using ASP.NET Consultation
最後,輸入欲新增的帳號與密碼即完成帳號的新增工作
Finally, enter the account and password that you want to add to complete the new task of the account
要設定 Provider 並須使用 Visual Studio 2005 的工具,可在官方網站下載免費的 Visual Web Developer 2005 Express Edition,在這邊就不介紹下載與安裝的過程了。
To configure Provider and use the Visual Studio 2005 tool, Visual Web Development 2005 Express can be downloaded and installed on the official website.
打開【Visual Web Developer 2005 Express】,點選【檔案】【新網站】
Open [Visual Web Development 2005 Express]
在【New Web Site】對話框,選擇【ASP.NET 網站】,【位置】輸入此專案的名稱與存放位置,決定好之後點選【確定】。
Enter the name and location of the project in the New Web site dialogue, select [ASP.NET website], enter the name and location of the project, and make a decision to click later.
按下 OK 之後,即開始建立專案相關的檔案,建立完成後可以看到 Website1 這個專案下面有三個檔案,點選【web.config】修改連線字串。
Press OK to start creating project-related files. When created, it can be seen that there are three files below the Website1 project and click [web.config] to modify the string.
在<configuration> <appSettings/> 與 <system.web> 之間,修改原來的 <connectionStrings> 為下列資訊,請記得將資料庫伺服器名稱改為自己的資料庫伺服器名稱。
Change the original & & lt; Confuture Strings> between < Confuture> & lt; AppSettings/> and & lt; system.web> change the original & lt; Connection Strings> Remember to change the name of the database server to your own database server name for the following information.
<connectionStrings> <add name="AspNetSqlProvider" connectionString="server=資料庫伺服器名稱; database=aspnetdb; Trusted_Connection=True" /> </connectionStrings>
接著在 <system.web> 與 <system.web/> 之間,輸入下列資訊,基本上不需做任何修改;預設的 applicationName 為 applicationName="/" ,即將此介面或應用程式指定在根目錄下,如果有更改,則 membership 與 roleManager 的 applicationName 都必須更改。
Next, between & lt; system. web> and & lt; system. web/>, the following information is entered, essentially without any change; the default application name is applicationName="/", so that the interface or application is assigned to the root directory and, if changed, the numbership and rollManager application name must be changed.
最重要的是:此段程式碼與上一段連接字串程式碼,與稍後將修改的 WSS 網站與管理中心的 web.config 字串幾乎一模一樣的,也就是說,這邊的兩段程式碼,將來直接貼到 WSS 網站與管理中心的 web.config 即可,不過,管理中心在 roleManager 的部份還是有點不同,這些不同的部分與置放的位置後面再說明。
Most importantly, this code and the previous connection string code are almost identical to the later modified web.config string of the WSS website and management centre, which means that the two parts of the code here will be posted directly to the web.config of the WSS website and the management centre, although the management centre is still a little different in the part of the raleManager, which can be explained at the back of the location where the different parts are placed.
<membership defaultProvider="AspNetSqlMembershipProvider"> <providers> <remove name="AspNetSqlMembershipProvider" /> <add connectionStringName="AspNetSqlProvider" passwordAttemptWindow="10" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="true" applicationName="/" requiresUniqueEmail="false" passwordFormat="Hashed" description="Stores and retrieves membership data from the Microsoft SQL Server database" name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" /> </providers> </membership> <roleManager enabled="true" defaultProvider="AspNetSqlRoleProvider"> <providers> <remove name="AspNetSqlRoleProvider" /> <add connectionStringName="AspNetSqlProvider" applicationName="/" description="Stores and retrieves roles data from the local Microsoft SQL Server database" name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" /> </providers> </roleManager>
當上述資訊輸入完成後,在【方案總管】點選最右邊的【ASP.NET 組態】,ASP.NET 即開始產生一個虛擬的 Web 應用程式管理介面。
When the above information input is completed, ASP.NET starts to create a virtual web application management interface by clicking on the rightmost [ASP.NET configuration] [Programme Manager].
Step 2-3. 建立使用者帳號
接下來我們使用 ASP.Net 網站管理工具來進行使用者帳號的建立。
Next, we use the ASP.Net website management tool to create a user account.
進到此網站管理工具頁面後,我們先確認此管理工具是否有連接到資料庫,且剛剛設定的相關提供者 (Provider) 是不是都正常連接;所以我們點選【提供者】頁簽,再點選【為每項功能選取不同的提供者 (進階)】。
When we enter the website management tool page, we confirm whether the management tool is connected to the database and whether the relevant provider (Provider) that has just been configured is properly connected; so we click on the [provider] page signature and click on the [selection of different providers (progress) for each function].
進入進階選項後,可看到如下的畫面,我們分別測試【成員資格提供者】與【角色提供者】,點選【測試】連結即可開始測試。
When you enter the advanced option, you can see the following scenes, where we differentiate between [member provider] and [play provider], and click on the [test] link to start the test.
只要連接成功,則測試會回傳【已順利建立與資料庫的連接】的資訊。
As long as the connection is successful, the test returns information [which has been created smoothly with the database].
連接沒問題後,點選【安全性】頁簽,準備選取驗證類型來更改驗證方式與增加使用者帳號;點選【選取驗證類型】。
After the connection is okay, click on the [security] page and prepare to select the authentication type to change the authentication method and increase the user account; click on the [checking for the authentication type].
選擇【從網際網路】,並按下【完成】
Select [from the Internet] and press [completed]
接下來直接點選【建立使用者】,當然您可以新增角色,但我們角色將使用 WSS 的角色,所以這邊不設定。
Next direct click [to create a user], of course you can add a new role, but our role will use the role of the WSS, so it is not set here.
點了建立使用者後,在下面的表單註冊帳戶資訊,如果剛有新增角色,則角色欄會出現可選取的角色,記得勾選【現用使用者】,然後按下【建立使用者】。
When a user is created, the following forms register information, and if there is a new role, the role column will have an optional role, and be sure to tick the [current user] and then press [create the user].
按下建立使用者後,出現【完成...】等資訊,按下【繼續】則可在新增使用者。
Click to create a user and then add information such as [finished...] and click to add a user.
當建立完成後,可以在【安全性】頁簽看到使用者與角色相關的資訊。
When built, information about the user and the role can be signed on the [security] page.
第三階段的工作有兩個重點,說難不難,因為我們剛剛已經在第二階段做了設定 Member 與 Provider 的工作,本階段就是要將第二階段的程式碼,加在 WSS 網站的 web.config 與管理中心的 web.config 裡。
The third phase has two main points, which are difficult to say, because we have just done the job of setting up Member and Provider in the second phase, which is to add the code of the second phase to the web.config of the WSS website and the management center web.config.
本階段您要完成下列兩個步驟:
You will complete the following two steps in this session:
Step 3-1. 修改 WSS 網站的 web.config
Step 3-1. Modify web.config of the WSS website
Step 3-2. 修改管理中心的 web.config
Step 3-2. Modification of management centre web.config
Step 3-1. 修改 WSS 網站的 web.config
首先,先確認所建立的網站是使用哪一個 Port,避免改錯檔案,接著到【C:\Inetpub\wwwroot\wss\VirtualDirectories】路徑下去找相對應的 Port Number,如這次要實作的是 80 Port,所以找到 80 資料夾,並點選 web.config 。
First, to determine which Port is used to avoid altering the files, then to find the corresponding Port Number under the path [C:\Innetpub\wwwroot\wss\VirtualDirectations] and, if 80 Port is to be implemented this time, to find 80 folders and click on web.config.
將之前在【Stage 2. 建立FBA資料庫與帳號】的 Step 2. 建立帳號輸入介面所編輯的 <connectionStrings> 程式碼照貼在 </SharePoint> 與 <system.web> 之間,資料庫伺服器名稱記得要改唷!
Step 2. Create an account to enter & lt; Connection Strings> coded in </SharePoint> and & & lt; system.web> Between, change the database server name!
<connectionStrings> <add name="AspNetSqlProvider" connectionString="server=資料庫伺服器名稱; database=aspnetdb; Trusted_Connection=True" /> </connectionStrings>
接著再把 Provider 資訊照貼在 <system.web> 之後
Then post Provider information on & lt;system. web>
<membership defaultProvider="AspNetSqlMembershipProvider"> <providers> <remove name="AspNetSqlMembershipProvider" /> <add connectionStringName="AspNetSqlProvider" passwordAttemptWindow="10" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="true" applicationName="/" requiresUniqueEmail="false" passwordFormat="Hashed" description="Stores and retrieves membership data from the Microsoft SQL Server database" name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" /> </providers> </membership> <roleManager enabled="true" defaultProvider="AspNetSqlRoleProvider"> <providers> <remove name="AspNetSqlRoleProvider" /> <add connectionStringName="AspNetSqlProvider" applicationName="/" description="Stores and retrieves roles data from the local Microsoft SQL Server database" name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" /> </providers> </roleManager>
整個位置的擺放如下圖所示,如此就完成了 WSS 網站 web.config 的更改,接下來繼續修改管理中心的 web.config。
The entire location is shown in the graph below, so that changes to the WSS website web.config are completed and the management centre web.config continues to be modified.
Step 3-2. 修改管理中心的 web.config
Step 3-2. Modify management centre web.config
如同修改 WSS 網站 web.config 的方式,先找到管理中心的資料夾,通常,管理中心的 Port 會是亂數,所以,只要找不是自己設定的 Port Number 就是了(如圖)。
As with the modification of the WSS website web.config, the folders are first found in the management centre, which is usually random in Port, so just look for Port Number, which is not your own setup.
打開之後呢,同樣的把 <connectionStrings> 貼在 </SharePoint> 與 <system.web> 之間,接著將 Provider 資訊照貼在正確的位置上。重點來了,在這邊要更改 <roleManager> 資訊。
When open, the same & lt; Connection Strings> pasted & lt;/SharePoint> and & lt; system.web> then posted the Provider information in the right place. The point is to change & lt; rollManager> information here.
之前所使用的 <roleManager> 是使用 AspNetSqlRoleProvider <roleManager enabled="true" defaultProvider="AspNetSqlRoleProvider"> 即,roleManager 角色管理的資訊是使用我們自訂的,但這樣的自訂無法與 WSS 3.0 整合起來,所以繼承 WSS 3.0 的角色管理資訊是最方便的。
& lt; raleManager> is used using AspNetSqlRoleProvider & lt; røleManager enabled= "true" defaultProvider="AspNetSqlRoleProvider"> i.e., røleManager role management information is used using our own custom, but this custom cannot be integrated with WSS 3.0, so it is most convenient to inherit WSS 3.0 role management information.
現在要將 <roleManager> 改為 AspNetWindowsTokenRoleProvider <roleManager enabled="true" defaultProvider="AspNetWindowsTokenRoleProvider"> 如此,便能使用 WSS 預設的角色管理模式了!
Now change & lt; raleManager> to AspNetWindowsToken RoleProvider & lt; raleManager enabled= "true" defaultProvider="AspNetWindowsToken RoleProvider"> so that the role management mode that WSS defaults can be used!
終於來到最後一個階段了,在最後的這個階段,要修改兩個部份的設定,分別是修改驗證提供者與新增管理者。
Finally, at the last stage, the two-part configuration is modified by modifying the certification provider and the new manager.
本階段您要完成下列兩個步驟:
You will complete the following two steps in this session:
Step 4-1. 修改驗證提供者:將驗證模式從 Windows 改為 Form 驗證模式
Step 4-1. Modify verification provider: change authentication mode from Windows to Form authentication mode
Step 4-2. 新增管理者:指定我們在 aspnetdb 所建立的使用者為管理者
Step 4-2. Add manager: designates the user we set up in aspnetdb as manager
Step 4-1. 修改驗證提供者
Step 4-1. Modified verification provider
進到【管理中心】【應用程式管理】在【應用程式安全性】點選【驗證提供者】。
Go to the [Managing Center] [Application Management] and click on the [Application Security] [Verification Providers].
進入【驗證提供者】在【Web 應用程式】可以看到現在的 Web 應用程式為何,且這個應用程式的【成員資格提供者名稱】為【Windows】,則直接點選【預設】。
Access [Verification provider] can see why the current Web application is available in [Web application], and the application's [name of the membership provider] is [Windows], which is directly clicked on [predicted].
在編輯驗證畫面裡
It's on the edit screen.
【驗證類型】選擇【表單】。
Could not close temporary folder: %s
勾選【啟用匿名存取】。
Check [enable anonymous access].
成員資格提供者名稱則輸入【AspNetSqlMembershipProvider】。
The name of the member qualification provider is entered in [AspNetSqlMembershipProvider].
角色管理員名稱輸入【AspNetSqlRoleProvider】,請確認輸入的字串是正確的!
Role Manager Name Enter [AspNetSqlRoleProvider]. Make sure the string is correct!
輸入完畢點選【儲存】。
Enter the final point [saved].
儲存之後,現在看到 Web 應用程式 http://wssfba 的成員資格提供者名稱已改為【AspNetSqlMembershipProvider】,這時到 http://wssfba 去看看。
After saving it, we now see that the name of the membership provider for the Web application http://wssfba has been changed to [AspNetSqlMembershipProvider], which will be visited at http://wsfba.
當進入網站,點選右上角的【登入】就會換成表單驗證的介面,要求輸入帳號與密碼
When you enter the site, click on the top right-hand corner for a form-test interface, requesting account and password.
耶!進入網站了,右上角顯示【歡迎 wssadmin】,不過,怎麼沒有管理網站的【網站動作】呢?那...這樣怎麼管理網站?所以,接下來的動作就是要將 wssadmin 變更為網站管理者!
Yeah! The top right corner shows "Welcome wsadmin," but why don't you run the website? So... how do you manage the website? So the next move is to change wsadmin to a website manager!
Step 4-2. 新增管理者
在應用程式管理,【應用程式安全性】點選【Web 應用程式的原則】。
On application management, click [application security] [Web application principles].
在【Web 應用程式的原則】點選【新增使用者】,當然先確認 Web 應用程式是否為正確要變更的 Web 應用程式。
Click [New Users] on [Web Application Principles] to confirm whether the web application is the correct web application to change.
在新增使用者頁,區域選擇【預設】,因為剛剛在建立驗證提供者時,區域是顯示【預設】,所以這邊選擇預設。
When you add a new user page, the area selects [premise] because the area displays [premise] just when the certification provider is established, this is where the default is selected.
在使用者新增【wssadmin】,並擊點右下角的【檢查名稱】圖示,只要有正確對應,且資料庫中有這個使用者,待名稱檢查完後,使用者 wssadmin 就會變成底線的 wssadmin,如此就可以確定此帳號與設定是沒有錯的;在【權限】勾選【完全控制-具有完全控制權】使 wssadmin 這個使用者可以去管理整個網站,點選【完成】。
When the user adds [wsadmin] and clicks on the [check name] icon at the lower right corner, the user wssadmin becomes the bottom wsadmin when the name is checked, so that it can be ascertained that the account and settings are correct; ticking [fully controlled - fully controlled] allows the user wsadmin to run the entire site and click [completely completed].
新增完畢後,可以看 Web 應用程式的原則,多了一個【預設】【angi】【aspnetsqlmembershipprovider:wssadmin】【完全控制】,這樣就成功了。
Once added, you can see the principles of the Web application with an additional [Agi] [aspnetsqlmembershipprovider: wssadmin], so it works.
再回到網站,登入後就可以看到【網站動作】。
Back to the site, you can see "Web Action" when you log in.
恭喜大家,終於完成了 WSS 3.0 Form 驗證的設定!
Congratulations on finally completing the WS 3.0 Form validation set!
在 WSSS 3.0 Form 驗證完成後,伴隨而來的問題是搜尋的問題,有關搜尋的議題,下回再做分享!
After the WSSS 3.0 Form validation is completed, the questions that follow are search questions, search questions, and share them next time!
注册有任何问题请添加 微信:MVIP619 拉你进入群

打开微信扫一扫
添加客服
进入交流群
发表评论