aspx代码如下
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="login1.aspx.cs" Inherits="login1" %>
<body><a>
<script type="text/javascript">
function $(id){
return document.getElementById(id);
}
window.onload = function(){$('username').focus();$('username').onkeydown = function(){
if(event.keyCode == 13){
$('password').select();
}
}
$('password').onkeydown = function(){
if(event.keyCode == 13){if(chklg())window.open('http://localhost/search/search.aspx','found','width=300,height=200')
}
}
}function chklg(){
if($('username').value != "sa"){
alert('用户名输入错误');
$('username').select();
return false;
}
if($('password').value != "sa"){
alert('密码输入错误');
$('password').select();
return false;
}
return true;
}function test(){if(chklg())
window.open('http://192.168.0.253/search/search.aspx','found','width=300,height=200')
}
</script>
<div style=" border:1px #ddd solid; overflow:hidden;text-align:center; float:center; margin:100px;">
<div style="textalign=center; margin-top:10px; margin-left:auto">
<div><p>用户名:<input type='text'; style="width:160px"; id="username"; name="username"></input></p></div><div id=usr></div>
</div>
<div style="position:relative; margin-top:10px; margin-left:auto;">
<div><p>密码: <input type="password"; style="width:160px"; id='password'; name='password'></input></p></div>
<div id=pwd></div>
</div><div style="margin-top:10px;margin-left:50px;"><input style="width:70px" type="submit"; value="登录" onclick="test()"></input></div>
</div>
</a></body></html>aspx.cs代码如下public partial class login1 : System.Web.UI.Page
{
  protected void Page_Load(object sender, EventArgs e)
  {
  if (!IsPostBack)
  {
  Session["name"] = ???;
  }
  }
}上面aspx.cs代码如何写才能将session写对啊? 就是说跳转到下一个页面(http://localhost/search/search.aspx)的时候,用Session["name"] 得到session值啊?

解决方案 »

  1.   

    你的意思是不是说JS验证正确后打开search.aspx这个页面。。而你就想在search.aspx这个页面获取用户登陆的用户名?
    1.你可以用Ajax.
    2.你可以在login1.aspx这个页面验证成功就就给SESSION赋值了..
      

  2.   

    现在情况是有个html页面能够直接输入地址访问,我想加个登陆页面,只有登陆的用户才允许访问这个html页面,那这个html页面能否用session["name"]来做是否已经登陆的用户的判断啊?
      

  3.   

    把html页面改成aspx页面不就好了么,html的部分不变,在.cs里面判断session。
      

  4.   

    现在情况是有个html页面能够直接输入地址访问,我想加个登陆页面,只有登陆的用户才允许访问这个html页面,那这个html页面能否用session["name"]来做是否已经登陆的用户的判断啊?
      

  5.   

    参考Session:http://www.cnblogs.com/insus/articles/2032508.html
    http://www.cnblogs.com/insus/articles/1429434.html