清華大佬耗費(fèi)三個(gè)月吐血整理的幾百G的資源,免費(fèi)分享!....>>>
ASP.NET Web Pages - WebSecurity 對(duì)象
描述
WebSecurity 對(duì)象提供 ASP.NET Web Pages 應(yīng)用程序的安全性和認(rèn)證。
通過(guò) WebSecurity 對(duì)象,您可以創(chuàng)建用戶(hù)帳戶(hù),登錄和注銷(xiāo)用戶(hù),重置或者更改密碼,以及其他更多與安全性相關(guān)的功能。
WebSecurity 對(duì)象參考手冊(cè) - 屬性
屬性 | 描述 |
---|---|
CurrentUserId | 獲取當(dāng)前登錄用戶(hù)的 ID。 |
CurrentUserName | 獲取當(dāng)前登錄用戶(hù)的名稱(chēng)。 |
HasUserId | 如果當(dāng)前有用戶(hù) ID,則返回 true。 |
IsAuthenticated | 如果當(dāng)前用戶(hù)是登錄的,則返回 true。 |
WebSecurity 對(duì)象參考手冊(cè) - 方法
方法 | 描述 |
---|---|
ChangePassword() | 為指定的用戶(hù)更改密碼。 |
ConfirmAccount() | 使用帳戶(hù)確認(rèn)令牌確認(rèn)帳戶(hù)。 |
CreateAccount() | 創(chuàng)建一個(gè)新的用戶(hù)帳戶(hù)。 |
CreateUserAndAccount() | 創(chuàng)建一個(gè)新的用戶(hù)帳戶(hù)。 |
GeneratePasswordResetToken() | 生成一個(gè)密碼重置令牌,可以在電子郵件中發(fā)送給用戶(hù)以便用戶(hù)可以重設(shè)密碼。 |
GetCreateDate() | 獲取指定會(huì)員創(chuàng)建的時(shí)間。 |
GetPasswordChangeDate() | 獲取密碼變更的日期和時(shí)間。 |
GetUserId() | 根據(jù)用戶(hù)名稱(chēng)獲取用戶(hù) ID。 |
InitializeDatabaseConnection() | 初始化 WebSecurity 系統(tǒng)(數(shù)據(jù)庫(kù))。 |
IsConfirmed() | 檢查用戶(hù)是否已被確認(rèn)。如果已確認(rèn),則返回 true。(例如,可通過(guò)電子郵件進(jìn)行確認(rèn)。) |
IsCurrentUser() | 檢查當(dāng)前用戶(hù)的名稱(chēng)是否與指定用戶(hù)名匹配。如果匹配,則返回 true。 |
Login() | 設(shè)置身份驗(yàn)證令牌,登錄用戶(hù)。 |
Logout() | 移除身份驗(yàn)證令牌,注銷(xiāo)用戶(hù)。 |
RequireAuthenticatedUser() | 如果用戶(hù)未通過(guò)身份驗(yàn)證,則設(shè)置 HTTP 狀態(tài)為 401(未經(jīng)授權(quán))。 |
RequireRoles() | 如果當(dāng)前用戶(hù)不是指定角色的成員,則設(shè)置 HTTP 狀態(tài)為 401(未經(jīng)授權(quán))。 |
RequireUser() | 如果當(dāng)前用戶(hù)不是指定用戶(hù)名的用戶(hù),則設(shè)置 HTTP 狀態(tài)為 401(未經(jīng)授權(quán))。 |
ResetPassword() | 如果密碼重置令牌是有效的,改變用戶(hù)的密碼為新密碼。 |
UserExists() | 檢查指定的用戶(hù)是否存在。 |
技術(shù)數(shù)據(jù)
名稱(chēng) | 值 |
---|---|
Class | WebMatrix.WebData.WebSecurity |
Namespace | WebMatrix.WebData |
Assembly | WebMatrix.WebData.dll |
初始化 WebSecurity 數(shù)據(jù)庫(kù)
如果您想在您的代碼中使用 WebSecurity 對(duì)象,首先您必須創(chuàng)建或者初始化 WebSecurity 數(shù)據(jù)庫(kù)。
在您的 Web 根目錄下,創(chuàng)建一個(gè)名為 _AppStart.cshtml 的頁(yè)面(如果已存在,則直接編輯頁(yè)面)。
將下面的代碼復(fù)制到文件中:
_AppStart.cshtml
@{
WebSecurity.InitializeDatabaseConnection("Users", "UserProfile", "UserId", "Email", true);
}
WebSecurity.InitializeDatabaseConnection("Users", "UserProfile", "UserId", "Email", true);
}
掃碼二維碼 獲取免費(fèi)視頻學(xué)習(xí)資料
- 本文固定鏈接: http://www.wangchenghua.com/j/aspnet/1000821/
- 免費(fèi): Python視頻資料獲取