在用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) then
7 FormsAuthentication.RedirectFromLoginPage(txtUserName.Text, _
8 false)
9 else
10 lblMessage.Text = "Not Authenticated:<br>" & txtUserName.Text & _
11 "<br>" & txtPassword.Text
12 end if
13 end sub
14</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) then
7 FormsAuthentication.SetAuthCookie(txtUserName.Text, _
8 false)
9 Response.redirect("default.aspx")
10 else
11 lblMessage.Text = "Not Authenticated:<br>" & txtUserName.Text & _
12 "<br>" & txtPassword.Text
13 end if
14 end sub
15</script>