asp.net前台的获取session该怎么写?
试用mininui做个测试,但不知道session怎么获取,烦请诸位大神帮忙!
前台:
<div>
<input id="tb" class="mini-textbox" />
</div>
<script type="text/javascript">
mini.parse();
// var myid = sessionStorage.getItem('ID');
// HttpSession session1 = request.getSession();
var str='<%=Session["ID"]%>';
alert(str);
var tb = mini.get("tb");
tb.setValue(tt);
</script>
前一个页面后台:
protected void Button1_Click(object sender, EventArgs e)
{
string msg = "";
string msg1 = "";
string str_id = "";
string str_pass = "";
if (Request["id"] != null)
{
str_id = Request["id"].ToString();
}
if (Request["pass"] != null)
{
str_pass = Request["pass"].ToString();
}
OleDbConnection ole_con = new OleDbConnection(Test.DBUtil.connectionString1);
if (ole_con.State == ConnectionState.Closed)
{
ole_con.Open();
}
if (ole_con.State == ConnectionState.Open)
{
OleDbCommand olecommand = new OleDbCommand("UAM_USER_LOGIN", ole_con);
string str_return = "";
try
{
olecommand.Parameters.Add("@VAR_ID", OleDbType.VarChar, 50);
olecommand.Parameters["@VAR_ID"].Direction = ParameterDirection.Input;
olecommand.Parameters.Add("@VAR_PASS", OleDbType.VarChar, 50);
olecommand.Parameters["@VAR_PASS"].Direction = ParameterDirection.Input;
olecommand.Parameters["@VAR_ID"].Value = txt_user.Text.ToString().Trim();
olecommand.Parameters["@VAR_PASS"].Value = txt_pass.Text.ToString().Trim();
olecommand.Parameters.Add("@STR_RETURN", OleDbType.VarChar, 50);
olecommand.Parameters["@STR_RETURN"].Direction = ParameterDirection.Output;
olecommand.CommandType = CommandType.StoredProcedure;
olecommand.ExecuteNonQuery();
str_return = olecommand.Parameters["@STR_RETURN"].Value.ToString();
}
catch (Exception ex)
{
str_return = ex.ToString();
}
finally
{
}
if (str_return == "SUCCEED")
{
// Session.Clear();
Session.Add("ID", str_id);
Session.Add("PASS", str_pass);
Response.Redirect("mainWeb/MainWeb.aspx", false);
}
else
{
msg1 = "用户名或密码错误!";
msg = "<script type='text/javascript'>alert('登录失败:" + msg1 + "');</script>";
Response.Write(msg);
}
if (ole_con.State == ConnectionState.Open)
{
ole_con.Close();
}
ole_con.Dispose();
}
页面能跳转,但无法取出session
上面的代码var str='<%=Session["ID"]%>';错误 424 应为标识符。
前台:
<div>
<input id="tb" class="mini-textbox" />
</div>
<script type="text/javascript">
mini.parse();
// var myid = sessionStorage.getItem('ID');
// HttpSession session1 = request.getSession();
var str='<%=Session["ID"]%>';
alert(str);
var tb = mini.get("tb");
tb.setValue(tt);
</script>
前一个页面后台:
protected void Button1_Click(object sender, EventArgs e)
{
string msg = "";
string msg1 = "";
string str_id = "";
string str_pass = "";
if (Request["id"] != null)
{
str_id = Request["id"].ToString();
}
if (Request["pass"] != null)
{
str_pass = Request["pass"].ToString();
}
OleDbConnection ole_con = new OleDbConnection(Test.DBUtil.connectionString1);
if (ole_con.State == ConnectionState.Closed)
{
ole_con.Open();
}
if (ole_con.State == ConnectionState.Open)
{
OleDbCommand olecommand = new OleDbCommand("UAM_USER_LOGIN", ole_con);
string str_return = "";
try
{
olecommand.Parameters.Add("@VAR_ID", OleDbType.VarChar, 50);
olecommand.Parameters["@VAR_ID"].Direction = ParameterDirection.Input;
olecommand.Parameters.Add("@VAR_PASS", OleDbType.VarChar, 50);
olecommand.Parameters["@VAR_PASS"].Direction = ParameterDirection.Input;
olecommand.Parameters["@VAR_ID"].Value = txt_user.Text.ToString().Trim();
olecommand.Parameters["@VAR_PASS"].Value = txt_pass.Text.ToString().Trim();
olecommand.Parameters.Add("@STR_RETURN", OleDbType.VarChar, 50);
olecommand.Parameters["@STR_RETURN"].Direction = ParameterDirection.Output;
olecommand.CommandType = CommandType.StoredProcedure;
olecommand.ExecuteNonQuery();
str_return = olecommand.Parameters["@STR_RETURN"].Value.ToString();
}
catch (Exception ex)
{
str_return = ex.ToString();
}
finally
{
}
if (str_return == "SUCCEED")
{
// Session.Clear();
Session.Add("ID", str_id);
Session.Add("PASS", str_pass);
Response.Redirect("mainWeb/MainWeb.aspx", false);
}
else
{
msg1 = "用户名或密码错误!";
msg = "<script type='text/javascript'>alert('登录失败:" + msg1 + "');</script>";
Response.Write(msg);
}
if (ole_con.State == ConnectionState.Open)
{
ole_con.Close();
}
ole_con.Dispose();
}
页面能跳转,但无法取出session
上面的代码var str='<%=Session["ID"]%>';错误 424 应为标识符。
...全文
请发表友善的回复…
发表回复