ความปลอดภัยของเว็บ - เข้าสู่ระบบ ()
❮ ความปลอดภัยของเว็บ
คำนิยาม
วิธีการเข้าสู่ระบบ () เข้าสู่ระบบผู้ใช้ที่ระบุโดยใช้ชื่อผู้ใช้และรหัสผ่าน
ไวยากรณ์ C# และ VB
WebSecurity.Login(userName,
password, persistCookie)
ตัวอย่าง
ตัวอย่าง C#
if (WebSecurity.Login(username,password))
{
<p>Welcome</p>
}
else
{
<p>Incorrect username or password.</p>
}
ตัวอย่าง VB
if WebSecurity.Login(username,password)
<p>Welcome</p>
else
<p>Incorrect username or password</p>
end if
พารามิเตอร์
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. |
คืนมูลค่า
Type | Description |
---|---|
Boolean | true if the user is logged in, otherwise false |
หมายเหตุ
เมื่อผู้ใช้เข้าสู่ระบบ ASP.NET จะตั้งค่าโทเค็นการพิสูจน์ตัวตนในคุกกี้ที่แจ้งให้ ASP.NET ทราบเมื่อมีการร้องขอต่อมาว่าผู้ใช้เข้าสู่ระบบแล้ว หาก ค่าคงอยู่ คุกกี้เป็นเท็จ โทเค็นจะถูกต้องจนกว่าผู้ใช้จะปิดเบราว์เซอร์ .
ข้อผิดพลาดและข้อยกเว้น
การเข้าถึงวัตถุWebSecurity จะส่ง InvalidOperationExceptionหาก:
- ยังไม่ได้เรียกเมธอดInitializeDatabaseConnection()
- SimpleMembershipไม่ได้เริ่มต้น (หรือปิดใช้งานในการกำหนดค่าเว็บไซต์)
❮ ความปลอดภัยของเว็บ