在用ASP.NET做WEB开发时,一般可以用FORM验证,它使用起来相对简单,也可以提升自己网站的安全性,下面是初学代码.请各位大侠多多指教.
![](/Images/OutliningIndicators/ContractedBlock.gif)
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
1
<configuration>
2
<system.web>
3
<authentication mode = "Forms">
4
<forms name="ProgAspNetCookie" loginUrl="csLoginForm.aspx" />
5
</authentication>
6![](/Images/OutliningIndicators/None.gif)
7
<authorization>
8
<deny users="?" />
9
</authorization>
10
</system.web>
11
</configuration>
12![](/Images/OutliningIndicators/None.gif)
这里是DEMO页面
![](/Images/OutliningIndicators/ContractedBlock.gif)
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
1
<%@ Page Language="vb" %>
2
<script runat="server">
3![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
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![](/Images/OutliningIndicators/None.gif)
16![](/Images/OutliningIndicators/None.gif)
Example 19-8. Login form using SetAuthCookie in VB.NET
![](/Images/OutliningIndicators/ContractedBlock.gif)
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
1
<%@ Page Language="vb" %>
2
<script runat="server">
3![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
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>