Recommended: ASP Security: Simple Learning ASP Connection Database Method 1.Conn.open Provider=Microsoft.Jet.OLEDB.4.0;Data Source= & Server.mappath(/db/database.mdb) This uses the relative path method of the root directory to solve the entire website.
People who are new to ASP have never known session very well. I am talking about the simple use of session when doing simple background login:1: login.htm
I won't say much about this page. Add the form to write the administrator nickname to give the text box username
Write the password to give the text box userpass and add a submission button. Note: The action of the form is chklogin.asp
2: chklogin.asp
<!--#include file=conn.asp-->
<%set rs=server.CreateObject(adodb.recordset)
sql=select * from admin where username='&request.Form(username)&'
'The admin is the table name of the storage administrator account and password
rs.open sql,con,1,1
%>
<%if rs.eof then
response.Write does not have this administrator
else
%>
<%
username=trim(request.Form(username))
password=request.Form(password)
%>
<%if password=rs(userpass) then
session(admin)=ercifang
response.Redirect(manage.asp)
else
response.Write This page is a dedicated page for administrators
end if
%>
<%end if%>
Look at the red text, so a session was added to the administrator
Set the first line in manage.asp
<%if session(admin)=ercifang then
...
else
response.write Only administrators can access this page
end if%>
In this way, other people cannot manage this site when they directly access manage.asp.
The following is the code for login.htm:
| <html> <head> <meta http-equiv=Content-Type content=text/html; charset=gb2312> <title>Administrative login</title> <style type=text/css> .fengge{font-size:12px} </style> </head> <body> <form name=form1 method=post action=chklogin.asp> <table width=400 border=1 align=center class=fengge> <tr> <td width=129> </td> <td width=255> </td> </tr> <tr> <td><div align=right>Administrator name: </div></td> <td><input name=username type=text id=username></td> </tr> <tr> <td><div align=right>Manage password: </div></td> <td><input name=password type=password id=password></td> </tr> <tr> <td><div align=right></div></td> <td><input type=submit name=Submit value=submit> <input type=reset name=Submit value=Reset> </td> </tr> <tr> <td colspan=2><div align=right></div></td> </tr> </table> </form> </body> </html> |
Share: How to assign values to data table entity classes in .net I encountered a problem today, which is how to assign values to attributes in the data entity class. Because the DataSet is taken out from the database. It is very clumsy to assign values to attributes in the data entity class one by one, and our data tables have as many as 24. Searched online and wrote