频道直达 - 学院 - 下载 - 交易 - 截图 - 特效 - 字库 - 手册 - 排名-工具 - 繁體
设为首页
加入收藏
联系我们
建站搜索: 虚拟主机  域名注册   常用广告代码      用户注册 | 用户登陆
您当前的位置:中国建站之家 -> 网站开发 -> ASP -> 文章内容
精彩推荐
热门文章
· 注册码大全二
· 注册码大全四
· 注册码大全一
· 通过google 赶快来赚..
· [图文] 头像-qq头像(..
· 要10G免费网络硬盘的..
· 注册码大全三
· 注册码大全十
· [图文] 梦幻背景图片..
· [图文] 卡通动物图片..
相关文章
· 自定义组件之属性(Prop..
· DataView如何绑定Web Se..
· 用ASP.Net(C#)连接Oracl..
· 使用phplib7.2中的Templ..
· Google在芝加哥太阳时报..
· JSP中的TagLib应用(3-2)..
· 动画设计素材-月份图标3..
· 浅谈PHP语法(三)
· 关于Ajax.Net的快速入门..
· 网页设计配色应用实例剖..
代码例子 - Ask For Login
作者:未知  来源:转载  发布时间:2005-9-17 21:07:37  发布人:acx

减小字体 增大字体

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

[打 印]
[] [返回上一页] [收 藏]
上一篇文章:用户状态维护
∷相关文章评论∷    (评论内容只代表网友观点,与本站立场无关!) [更多评论...]
关于本站 - 网站帮助 - 广告合作 - 下载声明 - 友情连接 - 网站地图 - 人才招聘
网站合作、内容监督、商务咨询:QQ: 9576619
Copyright ? 2005--2008 中国建站之家版权所有
未经授权禁止转载、摘编、复制或建立镜像.如有违反,追究法律责任.
免责申明:中国建站之家(www.jz123.cn)上的所有提供下载的软件和资源
均来源于网络,为软件或程序作者提供和网友推荐收集整理而来,仅供学习
和研究使用。如有侵犯你的版权,请立即联系我们,本站将在3个工作日内删除。
粤ICP备05092265号