Keamanan Web - Masuk ()
Keamanan Web
Definisi
Metode Login() mencatat pengguna tertentu, menggunakan nama pengguna dan kata sandi.
Sintaks C# dan VB
WebSecurity.Login(userName,
password, persistCookie)
Contoh
Contoh C#
if (WebSecurity.Login(username,password))
{
<p>Welcome</p>
}
else
{
<p>Incorrect username or password.</p>
}
Contoh VB
if WebSecurity.Login(username,password)
<p>Welcome</p>
else
<p>Incorrect username or password</p>
end if
Parameter
Parameter | Type | Description |
---|---|---|
userName | String | The user name |
password | String | The user password |
persistCookie | String | true to specify that the authentication token in the cookie should be persisted beyond the current session; otherwise false. Default is false. |
Nilai Kembali
Type | Description |
---|---|
Boolean | true if the user is logged in, otherwise false |
Catatan
Saat pengguna masuk, ASP.NET menetapkan token otentikasi dalam cookie yang memungkinkan ASP.NET mengetahui permintaan berikutnya bahwa pengguna telah masuk. Jika persistentCookie salah, token hanya valid hingga pengguna menutup browser .
Kesalahan dan Pengecualian
Akses apa pun ke objek WebSecurity memunculkan InvalidOperationException jika:
- Metode InitializeDatabaseConnection() belum dipanggil
- SimpleMembership tidak diinisialisasi (atau dinonaktifkan dalam konfigurasi situs web)
Keamanan Web