📄 代码例子 - ask for login.htm
字号:
<TD bgColor=#297dff width=1> </TD></TR></TBODY></TABLE>
<TABLE border=0 cellPadding=0 cellSpacing=0 width=755>
<TBODY>
<TR vAlign=top>
<TD bgColor=#297dff width=1> </TD>
<TD width=753>
<TABLE border=0 cellPadding=0 cellSpacing=0 width="100%">
<TBODY>
<TR>
<TD bgColor=#297dff colSpan=2 height=20><FONT color=#ceffff> →
<A href="http://www.aspsky.net/article/index.asp?classid=2"><FONT
color=#ceffff>ASP技术</FONT></A> >> <A
href="http://www.aspsky.net/article/index.asp?classid=2&Nclassid=2"><FONT
color=#ceffff>ASP应用</FONT></A> >> 《代码例子 - Ask For
Login》</FONT></TD></TR>
<TR>
<TD bgColor=#586011 colSpan=2 height=1><SPACER type="block"
width="1"></TD></TR>
<TR>
<TD colSpan=2 height=7></TD></TR>
<TR>
<TD align=middle class=p4 colSpan=2><B>代码例子 - Ask For
Login</B></FONT><BR>2000-12-3 动网先锋 </TD></TR>
<TR>
<TD class=p4 colSpan=2>
<BLOCKQUOTE><BR>The need for a security system is obvious if your
pages include sensitive information.
<P></P>
<P>This sample shows you how to setup some of your pages to ask
for login if the user has not logged in yet. </P>
<P>2eNetWorX/dev site uses this kind of protection for interactive
pages and file downloads. </P>
<P>Let's assume that we have a page where the visitors can ask
questions. We want to make sure that the user <BR>has logged in
before being able to ask a question. </P>
<P>If the user has not logged in yet, we will ask for a login.
After a successful login, we will redirect the <BR>user to the
page requested. </P>
<P>First, we will have a common file to check for login. You need
to include this file into all the pages <BR>that require login.
</P>
<P>security.asp </P>
<P><%</P>
<P>bLoggedIn = (len(session("UserName")) > 0) </P>
<P>if bRequireLogin then<BR>'Login required<BR>if Not bLoggedIn
then<BR>'Not logged in, ask for login<BR>response.redirect
"login.asp?comebackto=" & _
<BR>request.servervariables("script_name") & "?" & _
<BR>server.urlencode(request.querystring)<BR>'Note how we
construct the page to come back<BR>end if<BR>end if</P>
<P>%> </P>
<P>login.asp </P>
<P>First thing to do in our login.asp page is to get the page
where the user is redirected from. The variable <BR>sReferer is
used to redirect back to the page the user has come from. </P>
<P>sGoBackTo variable will used in the <form> tag for
persisting this location when we submit the login form. </P>
<P><%</P>
<P>if request("comebackto") <> "" then<BR>sReferer =
request("comebackto")<BR>sGoBackTo = "?" &
request.querystring<BR>end if</P>
<P>if request("cmdLogin") <> "" then</P>
<P>'Login Form submitted<BR>sUserName =
request("txtUserName")<BR>sPassword = request("txtPassword")</P>
<P>'Check for username and password</P>
<P>if sUserName = "bill" And sPassword = "gates"
then<BR>bLoginSuccessful = True<BR>end if</P>
<P>session("UserName") = sUserName</P>
<P><BR>'After a successful login, let's send the user <BR>'back to
the page requested. The variable sReferer <BR>'holds the page to
go back, if it is empty, we should<BR>'redirect the user to our
default page.</P>
<P>if sReferer = "" then<BR>response.redirect
"index.asp"<BR>else<BR>response.redirect sReferer<BR>end if</P>
<P>else</P>
<P>'Display the Login Form</P>
<P>%></P>
<P><form action="login.asp<%=sGoBackTo%>"
method="post"><BR><input type="text"
name="txtUserName"><br><BR><input type="password"
name="txtPassword"><br><BR><input type="submit"
name="cmdLogin"><br><BR></form></P>
<P><%</P>
<P>end if</P>
<P>%> </P>
<P>testpage.asp </P>
<P>Now, all you need to do is setting bRequireLogin to True and
including the security.asp file. </P>
<P><%</P>
<P>bRequireLogin = True</P>
<P>%></P>
<P><!--#include file="security.asp"--> </P>
<P>Users should be logged in to see this text. </P>
<P>I hope this sample gives you a quick overview of a simple
security system implementation with ASP. </P>
<P>You are always welcome to express your feedback! </P>
<P>by Hakan Eskici <BR><BR><BR></P></BLOCKQUOTE></TD></TR>
<TR>
<TD class=p4 vAlign=top width="50%">
<BLOCKQUOTE>原作者:不详<BR>来 源:不详<BR>共有1609位读者阅读过此文<BR>【<A
href="http://bbs.aspsky.net/list.asp?boardid=1">发表评论</A>】
</BLOCKQUOTE></TD>
<TD class=p4 vAlign=top width="50%">
<P>
<LI><FONT color=#0772b1>上篇文章</FONT>:<A
href="http://www.aspsky.net/article/list.asp?id=1200">浏览器语种检测,适合于多语言版本的站点</A>
<BR>
<LI><FONT color=#0772b1>下篇文章</FONT>:<A
href="http://www.aspsky.net/article/list.asp?id=1202">在Javascript中为String对象添加trim,ltrim,rtrim方法</A>
</LI></TD></TR>
<TR>
<TD bgColor=#297dff class=p4 height=20 width="50%"><FONT
color=#ceffff> → 本周热门</FONT></TD>
<TD bgColor=#297dff class=p4 width="50%"><FONT color=#ceffff> →
相关文章</FONT></TD></TR>
<TR>
<TD bgColor=#586011 colSpan=2 height=1><SPACER type="block"
width="1"></TD></TR>
<TR>
<TD colSpan=2 height=7></TD></TR>
<TR>
<TD class=p4 vAlign=top width="50%">
<LI><A href="http://www.aspsky.net/article/list.asp?id=1510"
target=_top title="SQL Server 7.0 入门(一)">SQL Server 7.0
入门(...</A>[<FONT color=red>7239</FONT>]<BR>
<LI><A href="http://www.aspsky.net/article/list.asp?id=1540"
target=_top title=PHP4实际应用经验篇(1)>PHP4实际应用经验篇(1)</A>[<FONT
color=red>7135</FONT>]<BR>
<LI><A href="http://www.aspsky.net/article/list.asp?id=1536"
target=_top
title=无组件文件上传代码实例(支持多文件上传及文件和input域混合上传)>无组件文件上传代码实例(支持多文件上...</A>[<FONT
color=red>6029</FONT>]<BR>
<LI><A href="http://www.aspsky.net/article/list.asp?id=2557"
target=_top title=树型结构在ASP中的简单解决>树型结构在ASP中的简单解决</A>[<FONT
color=red>5757</FONT>]<BR>
<LI><A href="http://www.aspsky.net/article/list.asp?id=1545"
target=_top title=PHP4实际应用经验篇(6)>PHP4实际应用经验篇(6)</A>[<FONT
color=red>5599</FONT>]<BR>
<LI><A href="http://www.aspsky.net/article/list.asp?id=2563"
target=_top title=一个老个写的无组件上传>一个老个写的无组件上传</A>[<FONT
color=red>5014</FONT>]<BR>
<LI><A href="http://www.aspsky.net/article/list.asp?id=1542"
target=_top title=PHP4实际应用经验篇(3)>PHP4实际应用经验篇(3)</A>[<FONT
color=red>4731</FONT>]<BR></LI></TD>
<TD class=p4 vAlign=top width="50%">
<LI><A
href="http://www.aspsky.net/article/list.asp?id=1674">在ASP中如何将代码生成的文件设为只读</A><BR>
<LI><A href="http://www.aspsky.net/article/list.asp?id=1201">代码例子 -
Ask For Login</A><BR></LI></TD></TR>
<TR>
<TD colSpan=2 height=7></TD></TR></TBODY></TABLE>
<TD bgColor=#297dff width=1> </TD></TR></TBODY></TABLE>
<TABLE border=0 cellPadding=0 cellSpacing=0 width=755>
<TBODY>
<TR>
<TD bgColor=#297dff height=1><SPACER type="block"
width="1"></TD></TR></TBODY></TABLE>
<TABLE border=0 cellPadding=0 cellSpacing=0 width=755>
<TBODY>
<TR>
<TD align=middle height=30></TD></TR></TBODY></TABLE>
<TABLE border=0 cellPadding=0 cellSpacing=0 width=755>
<TBODY>
<TR>
<TD align=middle class=p2 width="100%">
<TABLE border=0 cellPadding=0 cellSpacing=0 width=755>
<TBODY>
<TR>
<TD align=middle class=p2 width="100%">
<P align=center><A
href="http://www.aspsky.net/produce/index.asp">客户服务</A> -- <A
href="http://www.aspsky.net/aspads.asp">广告合作</A> -- <A
href="http://www.aspsky.net/about.asp">关于本站</A> -- <A
href="http://www.aspsky.net/tell.asp">联系方法</A><BR><BR>动网先锋版权所有 <FONT
face=Verdana, size=1 Arial, Helvetica, sans-serif>Copyright ©
2000-2001 <B>AspSky<FONT color=#cc0000>.Net</FONT></B>, All Rights
Reserved .</FONT>
</P></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></CENTER></CENTER></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -