帝国软件
  设为首页 加入收藏 关于我们
 
解密帝国网站管理系统
栏 目:
 
您的位置:首页 > 技术文档 > ASP编程
代码例子 - Ask For Login
作者: 发布时间:2005-03-12 来源:
The need for a security system is obvious if your pages include sensitive information.

This sample shows you how to setup some of your pages to ask for login if the user has not logged in yet.

2eNetWorX/dev site uses this kind of protection for interactive pages and file downloads.

Let's assume that we have a page where the visitors can ask questions. We want to make sure that the user
has logged in before being able to ask a question.

If the user has not logged in yet, we will ask for a login. After a successful login, we will redirect the
user to the page requested.

First, we will have a common file to check for login. You need to include this file into all the pages
that require login.

security.asp

<%

bLoggedIn = (len(session("UserName")) > 0)

if bRequireLogin then
'Login required
if Not bLoggedIn then
'Not logged in, ask for login
response.redirect "login.asp?comebackto=" & _
request.servervariables("script_name") & "?" & _
server.urlencode(request.querystring)
'Note how we construct the page to come back
end if
end if

%>

login.asp

First thing to do in our login.asp page is to get the page where the user is redirected from. The variable
sReferer is used to redirect back to the page the user has come from.

sGoBackTo variable will used in the <form> tag for persisting this location when we submit the login form.

<%

if request("comebackto") <> "" then
sReferer = request("comebackto")
sGoBackTo = "?" & request.querystring
end if

if request("cmdLogin") <> "" then

'Login Form submitted
sUserName = request("txtUserName")
sPassword = request("txtPassword")

'Check for username and password

if sUserName = "bill" And sPassword = "gates" then
bLoginSuccessful = True
end if

session("UserName") = sUserName


'After a successful login, let's send the user
'back to the page requested. The variable sReferer
'holds the page to go back, if it is empty, we should
'redirect the user to our default page.

if sReferer = "" then
response.redirect "index.asp"
else
response.redirect sReferer
end if

else

'Display the Login Form

%>

<form action="login.asp<%=sGoBackTo%>" method="post">
<input type="text" name="txtUserName"><br>
<input type="password" name="txtPassword"><br>
<input type="submit" name="cmdLogin"><br>
</form>

<%

end if

%>

testpage.asp

Now, all you need to do is setting bRequireLogin to True and including the security.asp file.

<%

bRequireLogin = True

%>

<!--#include file="security.asp"-->

Users should be logged in to see this text.

I hope this sample gives you a quick overview of a simple security system implementation with ASP.

You are always welcome to express your feedback!

by Hakan Eskici

  
评论】【加入收藏夹】【 】【打印】【关闭
※ 相关链接
 ·一段测试不用COMMAND对象来调用存  (2005-03-12)
 ·将html源代码规范化,转换成XSL代  (2005-03-12)
 ·表示代码与逻辑代码分离  (2005-03-12)
 ·无组件文件上传代码实例(支持多  (2005-03-12)
 ·二文件上传,才30行代码  (2005-03-12)
 ·一段返回随机记录的代码  (2005-03-12)
 ·利用MSCHART画图的一段代码  (2005-03-12)
 ·可以近视替代remote script的代码  (2005-03-12)
 ·转换文本为超联和Email格式的代码  (2005-03-12)
 ·得到表中字段属性代码  (2005-03-12)

   栏目导行
  PHP编程
  ASP编程
  ASP.NET编程
  JAVA编程
   站点最新
·致合作伙伴的欢迎信
·媒体报道
·帝国软件合作伙伴计划协议
·DiscuzX2.5会员整合通行证发布
·帝国CMS 7.0版本功能建议收集
·帝国网站管理系统2012年授权购买说
·PHPWind8.7会员整合通行证发布
·[官方插件]帝国CMS-访问统计插件
·[官方插件]帝国CMS-sitemap插件
·[官方插件]帝国CMS内容页评论AJAX分
   类别最新
·在ASP中使用数据库
·使用ASP脚本技术
·通过启动脚本来感受ASP的力量
·学习使用ASP对象和组件
·解析asp的脚本语言
·初看ASP-针对初学者
·ASP开发10条经验总结
·ASP之对象总结
·ASP与数据库应用(给初学者)
·关于学习ASP和编程的28个观点
 
关于帝国 | 广告服务 | 联系我们 | 程序开发 | 网站地图 | 留言板 帝国网站管理系统