在用ASP.NET做WEB开发时,一般可以用FORM验证,它使用起来相对简单,也可以提升自己网站的安全性,下面是初学代码.请各位大侠多多指教.
1
<configuration>2
<system.web>3
<authentication mode = "Forms">4
<forms name="ProgAspNetCookie" loginUrl="csLoginForm.aspx" />5
</authentication>6

7
<authorization>8
<deny users="?" />9
</authorization>10
</system.web>11
</configuration>12

这里是DEMO页面
1
<%@ Page Language="vb" %>2
<script runat="server">3

Sub btn_Click()sub btn_Click(ByVal Sender as Object, _4
ByVal e as EventArgs)5
if FormsAuthentication.Authenticate(txtUserName.Text, _6
txtPassword.Text) then7
FormsAuthentication.RedirectFromLoginPage(txtUserName.Text, _8
false)9
else10
lblMessage.Text = "Not Authenticated:<br>" & txtUserName.Text & _11
"<br>" & txtPassword.Text12
end if13
end sub14
</script>15

16

Example 19-8. Login form using SetAuthCookie in VB.NET
1
<%@ Page Language="vb" %>2
<script runat="server">3

Sub btn_Click()sub btn_Click(ByVal Sender as Object, _4
ByVal e as EventArgs)5
if FormsAuthentication.Authenticate(txtUserName.Text, _6
txtPassword.Text) then7
FormsAuthentication.SetAuthCookie(txtUserName.Text, _8
false)9
Response.redirect("default.aspx")10
else11
lblMessage.Text = "Not Authenticated:<br>" & txtUserName.Text & _12
"<br>" & txtPassword.Text13
end if14
end sub15
</script>