ASP.NET Web Pages - WebSecurity 对象

သက်သေ

WebSecurity 对象提供为 ASP.NET Web Pages 应用程序提供安全和认证。

WebSecurity အပြည့်အဝါ အပိုင်းအခြား ကို အသုံးပြု၍ အသုံးပြုသူ အက်ဥ်လက်မှု ဖန်တီးထားသည်၊ အသုံးပြုသူ ဖွင့်ထားခြင်း နှင့် ပိတ်ထားခြင်း ပြီးဆုံးသည်၊ ပုဒ်မှား ပြောင်းလဲထားသည် နှင့်အတူ အသုံးပြုသည်။

WebSecurity အပြည့်အဝါ ကိုးကွယ်မှု စာအုပ် - အခြေခံ

အခြေခံ သက်သေ
CurrentUserId လက်ရှိ အသုံးပြုသူ ID ကို ပြန်လည်ပေးသည်。
CurrentUserName လက်ရှိ အသုံးပြုသူ အမည် ကို ပြန်လည်ပေးသည်。
HasUserId လက်ရှိ အသုံးပြုသူ အသင်းဝင် ID ကို ပြန်လည်ပေးသည်။ အခြားအားဖြင့် အမှန်ကို ပြန်လည်ပေးသည်。
IsAuthenticated လက်ရှိ အသုံးပြုသူ အခွင့်အရေး အခြေအနေ ကို ပြန်လည်ပေးသည်。

WebSecurity အပြည့်အဝါ ကိုးကွယ်မှု စာအုပ် - နည်းလမ်း

အခြေခံ သက်သေ
ChangePassword() အသုံးပြုသူ ပုဒ်မှား ကို ပြောင်းလဲထားသည်。
ConfirmAccount() အက်ဥ်လက်မှု အကိုင်းချိန် အကိုင်းခြင်း အကိုင်းချိန် နှင့် အက်ဥ်လက်မှု ကို ဖွင့်ပေးသည်。
CreateAccount() အသုံးပြုသူ အက်ဥ်လက်မှု အသစ် ကို ဖန်တီးထားသည်。
CreateUserAndAccount() အသုံးပြုသူ အက်ဥ်လက်မှု အသစ် ကို ဖန်တီးထားသည်。
GeneratePasswordResetToken() အသုံးပြုသူ အား အိမ်မှုဒ် ဖြင့် ပေးပို့နိုင်သော ပြောင်းလဲသော ပုဒ်မှား လက်မှတ် ကို ထူးခြားစေသည်。
GetCreateDate() သတ်မှတ်ထားသော အသင်းဝင် အက်ဥ်လက်မှု ကို ဖန်တီးထားသော ရက်စွဲ နှင့် စံတော်ချိန် ကို ပြန်လည်ပေးသည်。
GetPasswordChangeDate() သတ်မှတ်ထားသော အသင်းဝင် အက်ဥ်လက်မှု အက်ဥ်လက်မှု ပြောင်းလဲသော ရက်စွဲ နှင့် စံတော်ချိန် ကို ပြန်လည်ပေးသည်。
GetPasswordFailures
SinceLastSuccess()
ပြီးခဲ့သော အောက်ပါ အသုံးပြုသူ အသင်းဝင် အက်ဥ်လက်မှု ကို တွေ့ရှိသော အချိန် ကို ပြန်လည်ပေးသည်。
GetUserId() သတ်မှတ်ထားသော အသုံးပြုသူ အမည် အား အသုံးပြု၍ အသုံးပြုသူ ID ကို ပြန်လည်ပေးသည်。
GetUserIdFrom
PasswordResetToken ()
Return the user ID from the password reset token.
InitializeDatabaseConnection() Initialize the membership system by connecting to a database that contains user information.
IsAccountLockedOut() Indicate whether the specified membership account has been locked out due to too many failed password attempts.
IsConfirmed() Return a value indicating whether the user has been confirmed.
IsCurrentUser() Return a value indicating whether the username of the logged-in user matches the specified username.
Login() Log in the user.
Logout() Log out the user.
RequireAuthenticatedUser() If the user is not authenticated, set the HTTP status to 401 (Unauthorized).
RequireRoles() If the current user does not belong to the specified role, set the HTTP status code to 401.
RequireUser() If the current user is not the specified user, set the HTTP status to 401.
ResetPassword() Reset the password using the password reset token.
UserExists() Check if the user exists.

Technical Data

Name Value
Class WebMatrix.WebData.WebSecurity
Namespace WebMatrix.WebData
Assembly WebMatrix.WebData.dll

WebSecurity ဘဏ္ဍာင် စတင်ခွင့်ပြုခြင်း

WebSecurity အရာများ သုံးစွဲ ရွေးချယ် ခင်မှာ ဘဏ္ဍာင် WebSecurity ကို ဖန်တီးခြင်း သို့မဟုတ် စတင်ခွင့်ပြုခြင်း ပြုလုပ်ပါ。

web အမြင့် အားစိုက် တွင် _AppStart.cshtml စာကြောင်း ကို ဖန်တီးခြင်း သို့မဟုတ် ဖွဲ့စည်းခြင်း ပြုလုပ်ပါ。

အဆိုပါ ဖိုင် တွင် အောက်ပါ အရာများ သုံးစွဲ ရွေးချယ် ရန်အတွက်:

_AppStart.cshtml

@{
WebSecurity.InitializeDatabaseConnection("Users", "UserProfile", "UserId", "Email", 
true);
}

ဝတ္ထု စတင်တွေ့ဆုံသောအခါ အထက်အရာများ အား အပူတပြင်ဆုံး ပြောင်းလဲကာ ဘဏ္ဍာင် အချက်အလက် ကို စတင်ခွင့်ပြုသည်。

“Users” သည် WebSecurity ဘဏ္ဍာင် အမည်ဖြစ်ပါသည် (Users.sdf)。

“UserProfile” သည် အသုံးပြုသူ ပြင်ဆင်ချက် အချက်အလက် ပါဝင်သော ဘဏ္ဍာင် အချက်အလက် အမည်ဖြစ်ပါသည်。

"UserId" 包含用户 ID 的列的名称(主键)。

"Email" 是包含用户名称的列名。

最后一个参数 true 是一个逻辑值,指示应创建用户配置文件表和成员资格表(如果它们不存在),否则 false。

提示:尽管 true 指示自动创建数据库表,但数据库本身不会被自动创建。它必须存在。

WebSecurity 数据库

UserProfile 表中的每条记录代表一个用户,其中包括用户 ID (主键)和用户名称(email):

UserId Email
1 john@johnson.net
2 peter@peterson.com
3 lars@larson.eut

Membership 表包含成员资格信息,比如用户何时创建以及是否(以及何时)确认成员资格。

အသိအမှတ် အသား နှင့် တချို့ အချက်အလက် မပါဘူး (တချို့ အချက်အလက် မပါဘူး):

UserId ဖန်တီးချိန် အတည်ပြု
အက်ဖ်
ဆုံးဖြတ်
အတည်ပြု
နောက်ဆုံး
စာကြိုး အမှား
စာကြိုး စာကြိုးဖြင့် ပြောင်းလဲ
1 12.04.2012 16:12:17 NULL True NULL AFNQhWfy.... 12.04.2012 16:12:17

မှတ်ချက်အခြေခံ အချက်အလက် အား မြင်သင့် ဖြစ် လျှင် အခြေခံ အချက်အလက် ကို လက်တွေ့ အချက်အလက် ဖြင့် ဝင်ရောက်ပါ၍ တချို့ အချက်အလက် ကို လေ့လာပါ။

အကြမ်းအား အခြေခံ ဝင်ရောက်ခွင့်

သင်းသား ဝင်ရောက်သည့် ဝင်ရောက်ခွင့် အခြေခံ အချက်အလက် မပြည့်ဆုံး ဖြစ် လျှင် ဝင်ရောက်ခွင့် အချက်အလက် ကို အသုံးပြုခြင်း အတွက် အမှား ဖြစ်ပေါ်လာပါတယ်။

အခြေခံ လုပ်ငန်းပြုး ကို အခြေခံ လုပ်ငန်းပြုး နှင့် သင်းသား အခြေခံ လုပ်ငန်းပြုး မပြည့်ဆုံး ဖြစ် လျှင် အမှား ဖြစ်ပေါ်လာပါတယ်။ အမှား ကို ပြည့်ဆုံးရန် သင်းသား ဝင်ရောက်သည့် ဝင်ရောက်ခွင့် အခြေခံ အချက်အလက် ကို အခြေခံ အချက်အလက် ဖုံးစံ ဖြစ်သော ဝင်ရောက်ခွင့် အချက်အလက် ကို အသုံးပြုပါ။

<appSettings> 
<add key="enableSimpleMembership" value="true" /> 
</appSettings>