Dev004奚江華
Upcoming SlideShare
Loading in...5
×
 

Dev004奚江華

on

  • 980 views

 

Statistics

Views

Total Views
980
Views on SlideShare
980
Embed Views
0

Actions

Likes
0
Downloads
3
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • © 2006 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION. 09/01/09 15:24
  • © 2006 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION. 09/01/09 15:24
  • © 2006 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION. 09/01/09 15:24
  • © 2006 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION. 09/01/09 15:24
  • © 2006 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION. 09/01/09 15:24
  • © 2006 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION. 09/01/09 15:24
  • © 2006 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION. 09/01/09 15:24
  • © 2006 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION. 09/01/09 15:24
  • © 2006 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION. 09/01/09 15:24
  • © 2006 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION. 09/01/09 15:24
  • © 2006 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION. 09/01/09 15:24
  • © 2006 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION. 09/01/09 15:24
  • © 2006 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION. 09/01/09 15:24
  • © 2006 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION. 09/01/09 15:24
  • © 2006 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION. 09/01/09 15:24
  • © 2006 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION. 09/01/09 15:24
  • © 2006 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION. 09/01/09 15:24
  • © 2006 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION. 09/01/09 15:24
  • © 2006 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION. 09/01/09 15:24
  • © 2006 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION. 09/01/09 15:24
  • © 2006 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION. 09/01/09 15:24
  • © 2006 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION. 09/01/09 15:24
  • © 2006 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION. 09/01/09 15:24
  • © 2006 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION. 09/01/09 15:24
  • © 2006 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION. 09/01/09 15:24
  • © 2006 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION. 09/01/09 15:24
  • © 2006 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION. 09/01/09 15:24
  • © 2006 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION. 09/01/09 15:24
  • © 2006 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION. 09/01/09 15:24
  • © 2006 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION. 09/01/09 15:24

Dev004奚江華 Dev004奚江華 Presentation Transcript

  •  
  • ASP.NET 2.0 網站 帳號權限管理系統 - 深入應用與探索 奚江華 .NET 技術書籍作家
  • 常見的網站帳號權限系統開發議題
    • 需求
      • 網站存取必須具備安全性
      • 帳號與密碼的建立與管理
      • 使用者群組分類
      • 記錄保存使用者個人獨特資料
    • 缺點
      • 缺乏一致性與簡便性的開發與管理機制
      • 重複性建立登入控制項功能畫面
      • 重複造輪子與相容性
      • 人力與成本的重複浪費
      • 其他
  • ASP.NET 2.0 網站 帳號權限管理系統相關服務
    • Login 相關控制項
    • Membership 成員資格
    • Role 角色管理
    • Profile 使用者設定檔
  • 對應功能意義說明 Membership 成員資格 Role 角色管理 Profile 使用者設定檔 使用者帳號 / 密碼 使用者群組 使用者屬性設定儲存 Login 相關控制項 現成登入 UI 介面
  • 設定帳號權限系統三步驟
    • 註冊資料庫
    • 修改資料庫連線設定
    • 測試 Provider 連線
  • Aspnet_regsql.exe 資料庫註冊
    • 建立並註冊 SqlMembershipProvider 及其他 SQL Server providers 的資料庫
  • 修改 Provider 資料庫連線字串
    • 以 ASP.NET 組態管理工具修改資料庫連線字串
  • 測試 Provider 連線
    • 以 ASP.NET 網站管理工具進行 Provider 連線測試
  • Login 登入相關控制項
    • 建立安全性網站登入 UI 介面及邏輯服務
    Login Password- Recovery LoginStatus LoginName LoginView CreateUser- Wizard Change- Password Membership & Role Management
  • Login 相關控制項功能說明 控制項 說明 Login 由帳號及密碼 TextBox 等所組成的一個控制項 。 LoginName 用於顯示登入的使用者名稱 。 LoginStatus 由登入狀態而顯示不同的登入提示 。 LoginView 依 Login 或 Logout 狀態而顯示不同的樣板或資訊 。 CreateUserWizard 提供建立使用者帳號的現成樣板精靈 。 ChangePassword 用於使用者變更密碼的時機 。 PasswordRecovery 用於使用者忘記密碼的時,提供密碼恢復的機制 。
  • Login 控制項 <html> <body> <form runat=&quot;server&quot;> <asp:Login RunAt=&quot;server&quot; /> </form> </body> </html>
  • CreateUserWizard 控制項
    • 建立使用者帳號精靈
  • ChangePassword 控制項
    • 變更使用者密碼
  • Membership 成員資格服務
    • 管理使用者帳號與認證
      • 以 ASP.NET 網站管理工具建立存取權
      • 經由 Membership API 達成程式化存取
    • 簡化 Forms 驗證
      • 提供驗證使用者姓名、密碼及建立使用者等邏輯
      • 管理身份認證、 E-Mail 及其他 Membership 資料儲存
    • 提供以 Provider-based 為基礎的彈性資料儲存
  • Membership 成員資格架構圖 Membership API Membership Data SQL Server Other Data Stores Controls Login LoginStatus LoginView SqlMembershipProvider Other Membership Providers Membership Providers Membership MembershipUser ActiveDirectory- MembershipProvider Active Directory Other Controls
  • 組成 Membership 服務之相關類別 類別或功能 說明 Membership 提供一般成員資格功能。 MembershipUser 提供特定使用者資訊。 MembershipProvider 定義可由成員資格系統使用的資料提供者功能。 MembershipProvider - Collection MembershipUser 物件的集合。 MembershipUser - Collection 當建立新的成員資格使用者時,提供成功或失敗 的描述值。 MembershipCreate - Status 當建立新的成員資格使用者時,提供成功或失敗 的描述值。 MembershipCreate - UserException 定義無法建立使用者時,所擲回的例外狀況。 MembershipPassword - Format 指定 ASP.NET 隨附之成員資格提供者可能會使用 的密碼儲存格式 (Clear 、 Hashed 和 Encrypted) 。
  • Membership 類別
    • 提供靜態方法來執行 Membership 主要功能任務
      • 建立與刪除使用者
      • 尋找使用者
      • 讀取使者資訊
      • 統計目前線上使用者
      • 產生亂數密碼
      • 驗證使用者身份
    • 包含讀取 Provider 設定的相關靜態 Properties 屬性
  • Membership 類別常用方法 方法 說明 CreateUser 建立使用者 。 DeleteUser 刪除使用者 。 GeneratePassword 產生指定長度的亂數密碼 。 取得 Membership 資料庫中所有 MembershupUser 物件 的集合 。 GetUser 讀取一個代表使用者的 MembershupUser 物件 。 UpdateUser 更新指定的使用者資料 。 ValidateUser 驗證使用者登入的姓名與密碼 。 GetAllUsers FindUserByName 以姓名尋找使用者帳號 。 取得目前存取應用程式的 Online 使用者人數 。 GetNumberOfUsers- Online
  • 建立新的使用者帳號 try { Membership.CreateUser (&quot;Jeff&quot;, &quot;imbatman!&quot;, &quot;jeffpr@microsoft.com&quot;); } catch (MembershipCreateUserException e) { switch (e.StatusCode) { case MembershipCreateStatus.DuplicateUsername: ... case MembershipCreateStatus.DuplicateEmail: ... case MembershipCreateStatus.InvalidPassword: ... default: ... } }
  • 使用者登入身份驗證 if (Membership.ValidateUser (UserName.Text, Password.Text)) FormsAuthentication.RedirectFromLoginPage (UserName.Text, RememberMe.Checked);
  • MembershipUser 類別
    • 表示單一 Membership 使用者物件
    • 包含非常多的使用者 Properties 屬性( set & get )
    • 包含讀取使用者資訊、改變或重設密碼、改變或重設密碼問題提示與回答等等
    • 經由 Membership 類別的 GetUser() 或 CreateUser() 方法回傳一個 MembershipUser 物件
  • MembershipUser 類別常用屬性 Comment 取得或設定成員資格使用者的應用程式特定資訊。 CreationDate 取得建立使用者帳號的日期和時間。 Email 取得或設定使用者的電子郵件地址。 LastLoginDate 取得或設定使用者上一次登入的日期和時間。 LastPasswordChangedDate 取得使用者密碼的上一次更新日期和時間。 PasswordQuestion 取得使用者的安全性密碼問題。 UserName 取得使用者登入的名稱。 屬性 說明
  • MembershipUser 類別常用方法 ChangePassword 變更使用者的密碼。 ChangePassword- QuestionAndAnswer 變更使用者的密碼安全性問題和解答。 GetPassword* 取得使用者的密碼(前提必須以 Clear Text 儲存)。 ResetPassword** 將使用者的密碼重新設定,並自動產生新的密碼。 * 必須 Membership.EnablePasswordRetrieval 屬性設定為 true UnlockUser 解除使用者帳號鎖定,以便能夠進行身份驗證。 ** 必須 Membership.EnablePasswordReset 屬性設定為 true 方法 說明
  • 解除使用者帳號鎖定 MembershipUser user = Membership.GetUser (&quot;Jeff&quot;); if (user != null) { if (user.IsLockedOut) { user.UnlockUser (); // TODO: Optionally use // MembershipUser.ResetPassword // to reset Jeff's password } }
  • Membership Providers
    • Membership 以 provider-based 為基礎的設計
      • Provider 提供 Membership 服務與資料儲存間的一個介面
    • 內建兩種 M embership providers
      • SqlMembershipProvider
      • ActiveDirectoryMembershipProvider
    • 可為其他類型 Membership 資料儲存客製化 Provider
  • SqlMembershipProvider 組態設定 <membership ...> <providers> <add name=&quot;AspNetSqlMembershipProvider&quot; connectionStringName=&quot;LocalSqlServer&quot; applicationName=&quot;/&quot; requiresUniqueEmail=&quot;[true|false]&quot; passwordFormat=&quot;[Clear|Encrypted|Hashed]&quot; maxInvalidPasswordAttempts=&quot;5&quot; passwordAttemptWindow=&quot;10&quot; passwordStrengthRegularExpression=&quot;&quot; minRequiredPasswordLength=&quot;7&quot; minRequiredNonalphanumericCharacters=&quot;1&quot; ... /> </providers> </membership>
  • Role 角色管理服務
    • 以角色群組為基礎的安全性管理
      • 以 ASP.NET 網站管理工具建立存取權
      • 經由 Roles API 達成程式化存取
    • 以 Role 角色管理簡化 Forms 驗證程序
      • 在 Request 時將使用者對應到角色
      • 為角色資料提供儲存服務
    • 提供以 Provider-based 為基礎的彈性資料儲存
  • Role 角色管理架構圖 Roles API Roles Data SQL Server Other Data Stores Controls Login LoginStatus LoginView Role Providers Roles Other Controls SqlRole-Provider AuthorizationStore-RoleProvider Other Providers WindowsToken-RoleProvider Authorization Manager
  • 組成 Role 服務之相關類別 Roles 提供角色的一般管理功能。 RoleProvider 定義提供者必須實作給 Roles 類別使用的功能。 RoleManagerModule 將角色資訊加入至目前的 User 屬性。 RoleManagerEventArgs 定義傳遞給 RoleManager_GetRoles 事件的引數, 在 GetRoles 事件期間,提供目前使用者內容的存取。 RolePrincipal 當做 IPrincipal 物件並且快取使用者的角色。 類別或功能 說明
  • Roles 類別
    • Role 角色管理 API 的閘道
    • 提供靜態方法來執行 Role 角色管理主要功能任務
      • 顯示所有角色
      • 新增與刪除角色
      • 將使用者加入角色
      • 將使用者從角色中移除
      • 回傳使用者所屬角色群組。
      • 判斷使用者是否屬於某個群組
    • 包含讀取 Provider 設定的相關靜態 Properties 屬性
  • 啓用 Role 角色管理功能
    • 角色管理功能預設為關閉
    • 在 Web.config 啓用 Role 角色管理功能:
    <configuration> <system.web> <roleManager enabled=&quot;true&quot; /> </system.web> </configuration>
  • Roles 類別常用方法 方法 說明 AddUserToRole 將使用者加入角色。 CreateRole 建立角色。 DeleteRole 刪除角色。 GetRolesForUser 取得使用者所屬角色的清單。 GetUsersInRole 取得角色中所有使用者清單。 IsUserInRole 判斷使用者是否在指定的角色中。 RemoveUserFromRole 從一個角色中移除一個使用者。
  • 建立新的角色 if (!Roles.RoleExists (&quot;Developers&quot;)) { Roles.CreateRole (&quot;Developers&quot;); }
  • 將使用者加入到角色中
    • AddUserToRole (一對一)
    • AddUserToRoles (一對多)
    • AddUsersToRole (多對一)
    • AddUsersToRoles (多對多)
    string name = Membership.GetUser ().Username; Roles.AddUserToRole (name, &quot;Developers&quot;);
  • Role 角色管理功能組態設定 <roleManager enabled=&quot;[true|false]&quot; defaultProvider=&quot;AspNetSqlRoleProvider&quot; createPersistentCookie=&quot;[true|false]&quot; cacheRolesInCookie=&quot;[true|false]&quot; cookieName=&quot;.ASPXROLES&quot; cookieTimeout=&quot;00:30:00&quot; cookiePath=&quot;/&quot; cookieRequireSSL=&quot;[true|false]&quot; cookieSlidingExpiration=&quot;[true|true]&quot; cookieProtection=&quot;[None|Validation|Encryption|All]&quot; domain=&quot;&quot; maxCachedResults=&quot;25&quot; > ... </roleManager>
  • Role 角色管理 Providers
    • Role 角色管理以 provider-based 為基礎的設計
    • 內建三種 R ole providers
      • AuthorizationStoreRoleProvider (Authorization Manager, or &quot;AzMan&quot;)
      • SqlRoleProvider (SQL Server and SQL Server Express)
      • WindowsTokenRoleProvider (Windows)
    • 可為其他類型 Role 資料儲存客製化 Provider
  • ASP.NET 2.0 網頁授權 <configuration> <system.web> <authorization> <deny users=&quot;*&quot; /> <allow roles=&quot;Admin&quot; /> <allow users=&quot;Bob&quot; /> </authorization> </system.web> </configuration>
  • Membership and Roles
  • Profiles 使用者設定檔
    • 依個別使用者而永久性地儲存資料
      • 資料為強型別型式 (unlike session state)
      • 可以即時 Intellisense 顯示查詢 (unlike session state)
      • 永久有效 (unlike session state)
      • 同時支援驗證或匿名的使用者
    • 透過動態編譯繼承自 ProfileBase 類別來存取
    • 提供以 Provider-based 為基礎的彈性資料儲存
  • Profile 使用者設定檔架構圖 Profiles Profile Data Stores SQL Server Express Other Data Stores ProfileBase ProfileCommon (Autogenerated ProfileBase-Derivative) Other Profile Providers Profile Providers SqlProfileProvider SQL Server
  • 定義 Profile 使用者設定檔 <system.web> <profile> <properties> <add name=&quot;PostalCode&quot; type=&quot;System.Int32&quot;/> <add name=&quot; 生日 &quot; type=&quot;System.DateTime&quot;/> <add name=&quot; 學歷 &quot; type=&quot;System.String&quot;/> <add name=&quot; 星座 &quot; type=&quot;System.String&quot;/> <add name=&quot; 血型 &quot; type=&quot;System.String&quot;/> <add name=&quot; 職業 &quot; type=&quot;System.String&quot;/> </properties> </profile> </system.web>
  • 存取 Profile 使用者設定檔
  • Profile 群組
    • Profile Properties 可群組化分類
    • 以 <group> element 定義群組
    <profile>   <properties>     <add name=&quot; 體重 &quot; type=&quot;System.Int32&quot; />     <group name=&quot;Address&quot;>       <add name=&quot;Country&quot; type=&quot;System.String&quot; />       <add name=&quot;City&quot; type=&quot;System.String&quot; />       <add name=&quot;PostalCode&quot; type=&quot;System.Int32&quot; />     </group>   </properties> </profile>
  • 使用 Profile 群組
  • Profiles 支援的資料型別
    • Profiles 簡單基本型別
      • String, Int32, Int64, DateTime, Decimal, etc.
    • Profiles 亦支援客製化型別
      • Use type attribute to specify type
      • Use serializeAs attribute to specify serialization mode: Binary, Xml (default), or String
    • serializeAs=&quot;Binary&quot; types must be serializable
    • serializeAs=&quot;String&quot; types need type converters
  • 使用客製化資料型別 <configuration> <system.web> <profile> <properties> <add name=&quot;Cart&quot; type=&quot;ShoppingCart&quot; serializeAs=&quot;Binary&quot; /> </properties> </profile> </system.web> </configuration>
  • 匿名使用者 Profile
    • 產生獨一無二 GUID ,並附加在 Request 中
    • 選擇性儲存在 Client Cookies 中
    • Profile 預設不支援匿名使用者機制
    • 啓用匿名使用者 Profile 要件
      • Step 1: 在 Web.config 中啓用 anonymousIdentification
      • Step 2: Profile 欄位必須設定 allowAnonymous 為 true
    • 依匿名使用者 ID 來存放資料
  • 匿名使用者 Profile 設定 <configuration> <system.web> <anonymousIdentification enabled=&quot;true&quot; /> <profile> <properties> <add name=&quot;ScreenName&quot; allowAnonymous=&quot;true&quot; /> <add name=&quot;Posts&quot; type=&quot;System.Int32&quot; defaultValue=&quot;0 /> <add name=&quot;LastPost&quot; type=&quot;System.DateTime&quot; /> </properties> </profile> </system.web> </configuration>
  • Profile 事件
    • Profile service 和 anonymous identification service 所引發的 global events
    Global.asax Handler 名稱 說明 AnonymousIdentification_Creating 建立與管理匿名使用者身份識別。 Profile_MigrateAnonymous 匿名者 Profile 移轉事件。 Profile_Personalize Profile 的個人化事件。 Profile_ProfileAutoSaving Profile 的自動儲存事件。
  • Profile 事件程式 Global.asax <%@ Application Language=&quot;C#&quot; %> <script runat=&quot;server&quot;> // 移轉匿名使用者 Profile 設定檔 事件 void Profile_MigrateAnonymous (object sender, ProfileMigrateEventArgs args) { ... } //Profile 個人化事件 public void Profile_Personalize (object sender, ProfileEventArgs args) { ... } //Profile 自動化儲存事件 void Profile_ProfileAutoSaving (object sender, ProfileAutoSaveEventArgs args) { ... } </script>
  • Profile 使用者設定檔管理
    • System.Web.Profile.ProfileManager 類別方法
    方法 說明 DeleteProfiles 刪除多個用者 Profile 。 FindInactiveProfiles- ByUserName 尋找超過指定日期時間內沒登入的所有使用者的 Profile 。 GetAllProfiles 取得特定 data source 所有使用者的 Profile 。 取得超過指定日期時間內沒登入所有使用者 Profile 的數量。 GetNumberOfProfiles 取得特定 data source 所有使用者 Profile 的數量。 GetNumberOf- InactiveProfiles FindProfilesBy- UserName 尋找指定使用者名稱的 Profile 。 取得超過指定日期時間內沒登入的所有使用者 Profile 。 GetAllInactiveProfiles DeleteInactiveProfiles 刪除超過指定日期時間內沒登入使用者的 Profile 。 DeleteProfile 刪除單一使用者 Profile 。
  • Profiles
  • 參考資料
    • ASP.NET Quickstart Tutorial
      • http://quickstarts.asp.net/QuickStartv20/aspnet/Default.aspx
    • MSDN Library
      • 使用成員資格管理使用者
        • ms-help://MS.MSDNQTR.v80.cht/MS.MSDN.v80/MS.VisualStudio.v80.cht/
        • dv_aspnetcon/html/824c3a24-f0af-427c-a652-0d2d1e9397cd.htm
      • 使用 ASP.NET 角色管理授權
      • ms-help://MS.MSDNQTR.v80.cht/MS.MSDN.v80/MS.VisualStudio.v80.cht/
      • dv_vwdcon/html/17c98693-6cb9-4f60-acac-8b6dfeb1c94c.htm
    • Provider Toolkit
      • http://msdn.microsoft.com/asp.net/downloads/providers/default.aspx
  • 資源 User Groups http://www.microsoft.com/communities/ usergroups/default.mspx Technical Community Sites http://www.microsoft.com/taiwan/community/default.mspx Newsgroups http://www.microsoft.com/taiwan/community/newsgroups/dgbrowser/zh-tw/default.mspx Virtual Labs http://www.microsoft.com/technet/traincert/virtuallab/default.mspx MSDN & TechNet http://www.microsoft.com/taiwan/msdn http://www.microsoft.com/taiwan/technet Microsoft Learning and Certification http://www.microsoft.com/taiwan/learning/default.htm Technical Chats and Webcasts http://www.microsoft.com/taiwan/community/chat_list.aspx http://www.microsoft.com/taiwan/technet/webcast/default.aspx
  • © 2006 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.