ASP.NET ဝဘ်စာမျက်နှာများ - WebSecurity Object
ဖော်ပြချက်
WebSecurity Object သည် ASP.NET Web Pages အပလီကေးရှင်းများအတွက် လုံခြုံရေးနှင့် စစ်မှန်ကြောင်းအထောက်အထားပြခြင်းကို ပံ့ပိုးပေးပါသည်။
WebSecurity အရာဝတ္ထုဖြင့် သင်သည် အသုံးပြုသူအကောင့်များကို ဖန်တီးခြင်း၊ အကောင့်ဝင်ခြင်းနှင့် ထွက်အသုံးပြုသူများ၊ စကားဝှက်များကို ပြန်လည်သတ်မှတ်ခြင်း သို့မဟုတ် ပြောင်းလဲခြင်းနှင့် အခြားအရာများကို ပြုလုပ်နိုင်သည်။
WebSecurity Object ကိုးကား - Properties
Properties | Description |
---|---|
CurrentUserId | Gets the ID for the current user |
CurrentUserName | Gets the name of the current user |
HasUserId | Returns true if the current has a user ID |
IsAuthenticated | Returns true if the current user is logged in |
WebSecurity Object ရည်ညွှန်းချက် - နည်းလမ်းများ
Method | Description |
---|---|
ChangePassword() | Changes the password for a user |
ConfirmAccount() | Confirms an account using a confirmation token |
CreateAccount() | Creates a new user account |
CreateUserAndAccount() | Creates a new user account |
GeneratePasswordResetToken() | Generates a token that can be sent to as user by email |
GetCreateDate() | Gets the time the specified membership was created |
GetPasswordChangeDate() | Gets the date and time when password was changed |
GetUserId() | Gets a user ID from a user name |
InitializeDatabaseConnection() | Initializes the WebSecurity system (database) |
IsConfirmed() | Checks if a user is confirmed |
IsCurrentUser() | Checks if the current user matches a user name |
Login() | Logs the user in by setting a token in the cookie |
Logout() | Logs the user out by removing the token cookie |
RequireAuthenticatedUser() | Exits the page if the user is not an authenticated user |
RequireRoles() | Exits the page if the user is not a part of the specified roles |
RequireUser() | Exits the page if the user is not the specified user |
ResetPassword() | Changes a user's password using a token |
UserExists() | Checks if a given user exists |
WebSecurity Database ကို စတင်ခြင်း
သင့်ကုဒ်တွင် WebSecurity အရာဝတ္တုကို အသုံးမပြုမီတွင် သင်သည် WebSecurity ဒေတာဘေ့စ်တစ်ခုကို ဖန်တီးရန် သို့မဟုတ် အစပြုရပါမည်။
သင့်ဝဘ်၏ အမြစ်တွင် _AppStart.cshtml အမည်ရှိ စာမျက်နှာတစ်ခု ဖန်တီးပါ (သို့မဟုတ် စာမျက်နှာကို တည်းဖြတ်ပါ) ။
ဖိုင်အတွင်း အောက်ပါကုဒ်ကို ထည့်ပါ။
_AppStart.cshtml
@{
WebSecurity.InitializeDatabaseConnection("Users", "UserProfile",
"UserId", "Email", true);
}
ဝဘ်ဆိုက် (အက်ပ်လီကေးရှင်း) စတင်ချိန်တိုင်း အပေါ်ကကုဒ်က အလုပ်လုပ်ပါလိမ့်မယ်။ ၎င်းသည် WebSecurity ဒေတာဘေ့စ်ကို အစပြုသည်။
"အသုံးပြုသူများ" သည် WebSecurity database (Users.sdf) ၏ အမည်ဖြစ်သည်။
"UserProfile" သည် အသုံးပြုသူပရိုဖိုင်အချက်အလက်ပါရှိသော ဒေတာဘေ့စ်ဇယား၏အမည်ဖြစ်သည်။
"UserId" သည် အသုံးပြုသူ ID များ (ပင်မသော့) ပါ၀င်သော ကော်လံအမည်ဖြစ်သည်။
"အီးမေးလ်" သည် အသုံးပြုသူအမည်များပါရှိသော ကော်လံအမည်ဖြစ်သည်။
နောက်ဆုံး ကန့်သတ်ဘောင်မှာ true သည် အသုံးပြုသူပရိုဖိုင်နှင့် အဖွဲ့ဝင်ခြင်းဇယားများ မရှိလျှင် အလိုအလျောက် ဖန်တီးသင့်သည်ဟု ညွှန်ပြသော boolean တန်ဖိုး တစ်ခုဖြစ်သည် ။
ဒေတာဘေ့စ် ဇယားများ အလိုအလျောက် ဖန်တီးခြင်းကို အမှန် ဟု ညွှန်ပြ သော်လည်း ဒေတာဘေ့စ်ကိုယ်တိုင်က အလိုအလျောက် ဖန်တီးမည်မဟုတ်ပါ။ ရှိကိုရှိရမယ်။
WebSecurity ဒေတာဘေ့စ်
UserProfile ဇယားတွင် သုံးစွဲသူတစ်ဦးစီအတွက် မှတ်တမ်းတစ်ခုပါရှိသည်၊ အသုံးပြုသူ ID (ပင်မသော့) နှင့် အသုံးပြုသူ၏အမည် (အီးမေးလ်) တို့ပါရှိသည် ။
UserId | |
---|---|
1 | [email protected] |
2 | [email protected] |
3 | [email protected] |
အဖွဲ့ဝင်ခြင်းဇယား တွင် အသုံးပြုသူအား ဖန်တီးခဲ့သည့်အချိန်နှင့် (အချိန်နှင့်) အဖွဲ့ဝင်ခြင်းကို အတည်ပြုခြင်းရှိမရှိ စသည့် အဖွဲ့ဝင်အချက်အလက်များ ပါဝင်မည်ဖြစ်သည်။
ဤကဲ့သို့ (အချို့ကော်လံများကို မပြပါ)။
User Id |
Create Date |
Confirmation Token |
Is Confirmed |
Last Password Failure |
Password | Password Change |
---|---|---|---|---|---|---|
1 | 12.04.2012 16:12:17 | NULL | True | NULL | AFNQhWfy.... | 12.04.2012 16:12:17 |
ရိုးရှင်းသော အသင်းဝင်ဖွဲ့စည်းမှုပုံစံ
သင့်ဆိုက်သည် ASP.NET ဝဘ်စာမျက်နှာများအသင်းဝင်စနစ် SimpleMembership ကိုအသုံးပြုရန် ပြုပြင်မွမ်းမံပါက WebSecurity အရာဝတ္ထုကို အသုံးပြု၍ အမှားအယွင်းများ ရရှိနိုင်သည် ။
hosting ဝန်ဆောင်မှုပေးသူ၏ဆာဗာကို သင့်ဒေသခံဆာဗာထက် ကွဲပြားစွာ ပုံစံချထားပါက ၎င်းသည် ဖြစ်ပေါ်နိုင်သည်။ ၎င်းကိုဖြေရှင်းရန်၊ ဝဘ်ဆိုက်၏ Web.config ဖိုင်တွင် အောက်ပါဒြပ်စင်ကို ထည့်ပါ။
<appSettings>
<add key="enableSimpleMembership" value="true" />
</appSettings>