急,弹出登录框,进行身份验证! 打开一个页面,如何实现弹出登录框,进行身份验证,验证通过用户才能操作页面。是不是用“层”,具体怎么实现啊 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 该页使用Session判断如果Session为空的话,实现跳转登录页面 asp.net中不太容易实现实现弹出窗口这个功能。只有javascript可以,但是javascript又无法操作session. 在后台对Session进行判断,如果为空的话,使用this.Page.ClientScript.RegisterStartupScript(this.Page.GetType(), "tip", "JS函数();", true);调用JS代码,JS代码可以是用DOM在页面动态创建登录窗口或者将原先已经做好的窗口(就是层啦)的css值display从none改为block 如果不是用层 那就不用window.open这个方法弹出页面,而是用另外一种 具体我也忘了反正你不对弹出的页面进行操作完成是不能对别的页面进行操作的再就是用层,将页面其他的地方变灰 lnkLogin.Attributes.Add("onclick", "javascript:window.showModalDialog('Login.aspx', 'LoginWindow', 'dialogHeight:200px;dialogWidth:300px;status:no;scroll:no;help:no') "); 用脚本弹出一个登陆的窗体。。要不就直接转到登陆页面string strURL=request["ReturnURL"];//这个是用户请求的页面路径 System.Web.Security.FormsAuthentication.SetAuthCookie(user.Name,true);//给用户颁发Cookie凭证 if(strURL==null) { //用户原请求页面为空时 Reaponse.Redirect("aaa.aspx"); } else { Response.Redirect(strURL);//用户原请求页面不为空时,转到请求页面 } …… ==== 用户退出 System.Web.Security.FormsAuthentication.SignOut(); 有一个很简单的方法,就是你把弹出的登录框(就是DIV)的宽和高覆盖整个页面,就相当于把整个页面都锁定了一样,除非将登陆框隐藏掉或者登录成功才能再操作原先的页面 逻辑不是问题吧?给你个弹出层的比较经典的代码。这是以前在某个帖子里的某个网友贴出来的,我收藏了。你只需对下面的代码进行一些修改就OK了。<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>景变暗的div可拖动提示窗口</title> <script language="javascript"> function alertWin(title, msg, w, h){ var titleheight = "22px"; // 提示窗口标题高度 var bordercolor = "#666699"; // 提示窗口的边框颜色 var titlecolor = "#FFFFFF"; // 提示窗口的标题颜色 var titlebgcolor = "#666699"; // 提示窗口的标题背景色 var bgcolor = "#FFFFFF"; // 提示内容的背景色 var iWidth = document.documentElement.clientWidth; var iHeight = document.documentElement.clientHeight; var bgObj = document.createElement("div"); bgObj.style.cssText = "position:absolute;left:0px;top:0px;width:"+iWidth+"px;height:"+Math.max(document.body.clientHeight, iHeight)+"px;filter:Alpha(Opacity=30);opacity:0.3;background-color:#000000;z-index:101;"; document.body.appendChild(bgObj); var msgObj=document.createElement("div"); msgObj.style.cssText = "position:absolute;font:11px '宋体';top:"+(iHeight-h)/2+"px;left:"+(iWidth-w)/2+"px;width:"+w+"px;height:"+h+"px;text-align:center;border:1px solid "+bordercolor+";background-color:"+bgcolor+";padding:1px;line-height:22px;z-index:102;"; document.body.appendChild(msgObj); var table = document.createElement("table"); msgObj.appendChild(table); table.style.cssText = "margin:0px;border:0px;padding:0px;"; table.cellSpacing = 0; var tr = table.insertRow(-1); var titleBar = tr.insertCell(-1); titleBar.style.cssText = "width:100%;height:"+titleheight+"px;text-align:left;padding:3px;margin:0px;font:bold 13px '宋体';color:"+titlecolor+";border:1px solid " + bordercolor + ";cursor:move;background-color:" + titlebgcolor; titleBar.style.paddingLeft = "10px"; titleBar.innerHTML = title; var moveX = 0; var moveY = 0; var moveTop = 0; var moveLeft = 0; var moveable = false; var docMouseMoveEvent = document.onmousemove; var docMouseUpEvent = document.onmouseup; titleBar.onmousedown = function() { var evt = getEvent(); moveable = true; moveX = evt.clientX; moveY = evt.clientY; moveTop = parseInt(msgObj.style.top); moveLeft = parseInt(msgObj.style.left); document.onmousemove = function() { if (moveable) { var evt = getEvent(); var x = moveLeft + evt.clientX - moveX; var y = moveTop + evt.clientY - moveY; if ( x > 0 &&( x + w < iWidth) && y > 0 && (y + h < iHeight) ) { msgObj.style.left = x + "px"; msgObj.style.top = y + "px"; } } }; document.onmouseup = function () { if (moveable) { document.onmousemove = docMouseMoveEvent; document.onmouseup = docMouseUpEvent; moveable = false; moveX = 0; moveY = 0; moveTop = 0; moveLeft = 0; } }; } var closeBtn = tr.insertCell(-1); closeBtn.style.cssText = "cursor:pointer; padding:2px;background-color:" + titlebgcolor; closeBtn.innerHTML = "<span style='font-size:15pt; color:"+titlecolor+";'>×</span>"; closeBtn.onclick = function(){ document.body.removeChild(bgObj); document.body.removeChild(msgObj); } var msgBox = table.insertRow(-1).insertCell(-1); msgBox.style.cssText = "font:10pt '宋体';"; msgBox.colSpan = 2; msgBox.innerHTML = msg; // 获得事件Event对象,用于兼容IE和FireFox function getEvent() { return window.event || arguments.callee.caller.arguments[0]; } } </script> </head> <body> <input type="button" value="点这里" onclick="alertWin('标题','这里是内容',300,200);" /> </body> </html> 在Page_load里写 如果Session["user"]=null就弹出要求登录的层 使用模式窗体window.showModalDialog()在弹出的模式窗口页面中判断当前登录的用户名和密码是否正确,返回一个结果参数resultParam,然后在父窗体中读取到这个resultParam,根据resultParam再做进一步处理!具体window.showModalDialog()的使用方法,请Google. 如何分别调用js中的方法?在线等 关于js是否从外部调用的问题 觉得分层没什么意义。 asp.net远程连接Oracle vista下,如何在Web服务器上调试ASP.NET程序? 请问:创建文本文档的对象函数是什么? 是一个DLL好还是多个的好?表示层的话. 怎么用js读取.net写的cookie值? 简单的数据库连接问题,请指教 当点击ImageButton以后怎么能弹出一个新的窗口? 求把json字符串转换为json对象的方法 一个用datalist···来显示或者用repeater的问题·(急)
如果Session为空的话,实现跳转登录页面
再就是用层,将页面其他的地方变灰
lnkLogin.Attributes.Add("onclick", "javascript:window.showModalDialog('Login.aspx', 'LoginWindow', 'dialogHeight:200px;dialogWidth:300px;status:no;scroll:no;help:no') ");
要不就直接转到登陆页面
string strURL=request["ReturnURL"];//这个是用户请求的页面路径
System.Web.Security.FormsAuthentication.SetAuthCookie(user.Name,true);//给用户颁发Cookie凭证
if(strURL==null)
{
//用户原请求页面为空时
Reaponse.Redirect("aaa.aspx");
}
else
{
Response.Redirect(strURL);//用户原请求页面不为空时,转到请求页面
}
……
====
用户退出
System.Web.Security.FormsAuthentication.SignOut();
你只需对下面的代码进行一些修改就OK了。<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>景变暗的div可拖动提示窗口</title>
<script language="javascript">
function alertWin(title, msg, w, h){
var titleheight = "22px"; // 提示窗口标题高度
var bordercolor = "#666699"; // 提示窗口的边框颜色
var titlecolor = "#FFFFFF"; // 提示窗口的标题颜色
var titlebgcolor = "#666699"; // 提示窗口的标题背景色
var bgcolor = "#FFFFFF"; // 提示内容的背景色
var iWidth = document.documentElement.clientWidth;
var iHeight = document.documentElement.clientHeight;
var bgObj = document.createElement("div");
bgObj.style.cssText = "position:absolute;left:0px;top:0px;width:"+iWidth+"px;height:"+Math.max(document.body.clientHeight, iHeight)+"px;filter:Alpha(Opacity=30);opacity:0.3;background-color:#000000;z-index:101;";
document.body.appendChild(bgObj);
var msgObj=document.createElement("div");
msgObj.style.cssText = "position:absolute;font:11px '宋体';top:"+(iHeight-h)/2+"px;left:"+(iWidth-w)/2+"px;width:"+w+"px;height:"+h+"px;text-align:center;border:1px solid "+bordercolor+";background-color:"+bgcolor+";padding:1px;line-height:22px;z-index:102;";
document.body.appendChild(msgObj);
var table = document.createElement("table");
msgObj.appendChild(table);
table.style.cssText = "margin:0px;border:0px;padding:0px;";
table.cellSpacing = 0;
var tr = table.insertRow(-1);
var titleBar = tr.insertCell(-1);
titleBar.style.cssText = "width:100%;height:"+titleheight+"px;text-align:left;padding:3px;margin:0px;font:bold 13px '宋体';color:"+titlecolor+";border:1px solid " + bordercolor + ";cursor:move;background-color:" + titlebgcolor;
titleBar.style.paddingLeft = "10px";
titleBar.innerHTML = title;
var moveX = 0;
var moveY = 0;
var moveTop = 0;
var moveLeft = 0;
var moveable = false;
var docMouseMoveEvent = document.onmousemove;
var docMouseUpEvent = document.onmouseup;
titleBar.onmousedown = function() {
var evt = getEvent();
moveable = true;
moveX = evt.clientX;
moveY = evt.clientY;
moveTop = parseInt(msgObj.style.top);
moveLeft = parseInt(msgObj.style.left);
document.onmousemove = function() {
if (moveable) {
var evt = getEvent();
var x = moveLeft + evt.clientX - moveX;
var y = moveTop + evt.clientY - moveY;
if ( x > 0 &&( x + w < iWidth) && y > 0 && (y + h < iHeight) ) {
msgObj.style.left = x + "px";
msgObj.style.top = y + "px";
}
}
};
document.onmouseup = function () {
if (moveable) {
document.onmousemove = docMouseMoveEvent;
document.onmouseup = docMouseUpEvent;
moveable = false;
moveX = 0;
moveY = 0;
moveTop = 0;
moveLeft = 0;
}
};
}
var closeBtn = tr.insertCell(-1);
closeBtn.style.cssText = "cursor:pointer; padding:2px;background-color:" + titlebgcolor;
closeBtn.innerHTML = "<span style='font-size:15pt; color:"+titlecolor+";'>×</span>";
closeBtn.onclick = function(){
document.body.removeChild(bgObj);
document.body.removeChild(msgObj);
}
var msgBox = table.insertRow(-1).insertCell(-1);
msgBox.style.cssText = "font:10pt '宋体';";
msgBox.colSpan = 2;
msgBox.innerHTML = msg;
// 获得事件Event对象,用于兼容IE和FireFox
function getEvent() {
return window.event || arguments.callee.caller.arguments[0];
}
}
</script>
</head>
<body>
<input type="button" value="点这里" onclick="alertWin('标题','这里是内容',300,200);" />
</body>
</html>
就弹出要求登录的层
在弹出的模式窗口页面中判断当前登录的用户名和密码是否正确,返回一个结果参数resultParam,
然后在父窗体中读取到这个resultParam,根据resultParam再做进一步处理!具体window.showModalDialog()的使用方法,请Google.