string
test
=
"
username
"
;
private void Page_Load( object sender, System.EventArgs e)
{
if(Application["User_" + test] == null || Application["User_" + test].ToString() != Request.UserHostAddress)
Session["login"] = null;
else
Response.Write(Session["login"].ToString() + "已登录<br>");
}
private void Button1_Click( object sender, System.EventArgs e)
{
Session["login"] = test;
Application["User_" + test] = Request.UserHostAddress;
}
private void Page_Load( object sender, System.EventArgs e)
{
if(Application["User_" + test] == null || Application["User_" + test].ToString() != Request.UserHostAddress)
Session["login"] = null;
else
Response.Write(Session["login"].ToString() + "已登录<br>");
}
private void Button1_Click( object sender, System.EventArgs e)
{
Session["login"] = test;
Application["User_" + test] = Request.UserHostAddress;
}
ASP程序中同一个用户不允许同时登陆两次
登陆页login.asp:
<%
if request.Form.count > 0 then
session( " username " ) = request( " username " )
application(session( " username " )) = session.SessionID
response.Redirect( " index.asp " )
end if
%>
< form method = post action = "" >
< input type = " text " name = " username " >< input type = " submit " >
</ form >
其他需要认证的页面index.asp:
<%
if application(session( " username " )) = session.SessionID then
response.Write( " 已经登陆 " )
else
response.Write( " 没有登陆 " )
end if
%>
登陆页login.asp:
<%
if request.Form.count > 0 then
session( " username " ) = request( " username " )
application(session( " username " )) = session.SessionID
response.Redirect( " index.asp " )
end if
%>
< form method = post action = "" >
< input type = " text " name = " username " >< input type = " submit " >
</ form >
其他需要认证的页面index.asp:
<%
if application(session( " username " )) = session.SessionID then
response.Write( " 已经登陆 " )
else
response.Write( " 没有登陆 " )
end if
%>