各位大侠帮忙解决一下c# session的问题
我在登陆页面的登陆按钮里面设置了把UserName放入Session里面
public string MessageBox(string txt,string Url) { string str; str = "<script language=javascript>alert('"+txt+"');location='"+Url+"'</script>"; return str; } protected void Button1_Click(object sender, EventArgs e) { if (i == 1) { if(bc.seleSQL("select count(*) from Usersmr where UserName='"+UserName.Text+"' AND UserPwd='"+UserPwd.Text+"'AND Roled='"+qx+"'")) { Session["loginName"] = UserName.Text; Response.Write(bc.MessageBox("学生登陆成功","../student/Text.aspx")); } else { Response.Write(bc.MessageBox("登录失败,请输入正确的用户名或者密码","Login.aspx")); } } if(i==0) { if(bc.seleSQL("select count(*) from Usersmr where UserName='"+UserName.Text+"' AND UserPwd='"+UserPwd.Text+"'AND Roled='"+qxa+"'")) { Session["loginName"] = UserName.Text; Response.Write(bc.MessageBox("教师登陆成功","../teacher/teacher.aspx")); } else { Response.Write(bc.MessageBox("登录失败,请输入正确的用户名或者密码","Login.aspx")); } } }using System;using System.Collections;using System.Configuration;using System.Data;using System.Linq;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.HtmlControls;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Xml.Linq;public partial class teacher_teacher : System.Web.UI.Page{ string a, b; protected void Page_Load(object sender, EventArgs e) { try { a = Session["loginName"].ToString(); //Label1.Text = a; DataBase bc = new DataBase(); Response.Write(bc.MessageBox(a)); //bc.createCon(); //b=bc.getRead("select DepartmentId from Usersmr where UserName='"+a+"'"); //Label2.Text = b; } catch (Exception z) { } } protected void Button1_Click(object sender, EventArgs e) { }}
System.Web.UI.WebControls.ParameterCollection.GetValues(HttpContext context, Control control) +301
System.Web.UI.WebControls.SqlDataSourceView.InitializeParameters(DbCommand command, ParameterCollection parameters, IDictionary exclusionList) +264
System.Web.UI.WebControls.SqlDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +472
System.Web.UI.WebControls.BaseDataList.GetData() +38
System.Web.UI.WebControls.DataList.CreateControlHierarchy(Boolean useDataSource) +153
System.Web.UI.WebControls.BaseDataList.OnDataBinding(EventArgs e) +54
System.Web.UI.WebControls.BaseDataList.DataBind() +55
System.Web.UI.WebControls.BaseDataList.EnsureDataBound() +60
System.Web.UI.WebControls.BaseDataList.CreateChildControls() +69
System.Web.UI.Control.EnsureChildControls() +87
System.Web.UI.Control.PreRenderRecursiveInternal() +44
System.Web.UI.Control.PreRenderRecursiveInternal() +171
System.Web.UI.Control.PreRenderRecursiveInternal() +171
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +842
--------------------------------------------
版本信息: Microsoft .NET Framework 版本:2.0.50727.3053; ASP.NET 版本:2.0.50727.3053
[解决办法]
参考:
http://www.cnblogs.com/insus/articles/2032508.html