优秀的软件开发团队:深圳升蓝软件 数据库开发 .Net技术  |  ASP技术 PHP技术 JSP技术 应用技术类     
热门推荐
升蓝OA办公自动化系统
基于.Net技术的网络
协同办公环境
 
ASP基础
数据库相关
安全加密
全文检索
ASP应用
打印相关
客户端相关
XML相关
系统相关
正则表达式
ASP技巧
组件开发
脚本编码
FSO专题
邮件相关
远程脚本
性能优化
 
相关链接
深圳升蓝软件:系统集成、办公自动化平台、电子商务、电子政务、Web数据库、企业网站、游戏、手机应用程序、CDMA软件、电子出版物等,为客户提供优秀的解决方案
 
升蓝(www.hi-blue.com)为企业管理、政府办公提供成熟的、易于实施的IT技术服务,我们的解决方案包括OA办公自动化系统CRM客户关系管理系统ERP企业生产管理和订单管理系统电子政务系统、知识管理系统、企业门户、商业智能、工程项目管理等等...
 
电子政务解决方案
塑料/橡胶管理系统
知识管理系统简介
多媒体光盘方案
ERP企业资源管理
订单计划管理系统
PM工程项目管理系统
会员管理系统
相关资料下载
OA办公自动化系统
CRM客户关系管理系统
在线试用版本说明
OA 系统的用户手册
 
 
 
 
升蓝开发团队 > 技术资料 > ASP技术 > ASP应用 : 代码例子 - Ask For Login

代码例子 - Ask For Login


March 25,2004
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
       
数据库开发 | .Net技术 | ASP技术 | PHP技术 | JSP技术 | 应用技术类 | 升蓝开发小组
Copyright ? 2001-2004 Shenzhen Hi-blue Software Team 升蓝开发小组 All rights reserved