login.aspx页面
取Session值代码如下:Session["zmadmin"]=Label1.Text.ToString();Session["zmpwd"]=Label2.Text.ToString();Session["zmpopid"]=Label3.Text.ToString();Response.Write(Session["zmadmin"].ToString()); (确定可以在字幕上打印出结果并且正确)Response.Redirect("test.aspx");
test.aspx页面
private void Page_Load(object sender, System.EventArgs e)
{
if(Session["zmadmin"] != null)
{
Label1.Text=Session["zmadmin"].ToString();
}
else
{
Label1.Text="Session值为空";
}
}屏幕上打印出:Session值为空
我确定在web.config里的设置正确,为什么会出现这样的情况,请帮帮小弟,谢谢
取Session值代码如下:Session["zmadmin"]=Label1.Text.ToString();Session["zmpwd"]=Label2.Text.ToString();Session["zmpopid"]=Label3.Text.ToString();Response.Write(Session["zmadmin"].ToString()); (确定可以在字幕上打印出结果并且正确)Response.Redirect("test.aspx");
test.aspx页面
private void Page_Load(object sender, System.EventArgs e)
{
if(Session["zmadmin"] != null)
{
Label1.Text=Session["zmadmin"].ToString();
}
else
{
Label1.Text="Session值为空";
}
}屏幕上打印出:Session值为空
我确定在web.config里的设置正确,为什么会出现这样的情况,请帮帮小弟,谢谢
解决方案 »
- 网络视频流数据,保存到本地mpg格式视频文件
- FileStream保存txt文件时如何设置编码为UTF-8?
- 如果没有.netframework是否可以在IIS下面运行asp.net
- c# 获取另一窗体textbox的值
- 如何用Windows media SDK 开发C/S应用程序,请大家进来来看看
- C#中的 ExecuteNonQuery Executedatareader ExecuteSclar 有啥区别 具体都啥时候
- WinForm中怎么刷新窗体??!
- 求问怎么下载地址加上随机数字串的验证码
- 请教各位:哪本书更适合我?(在线等待)
- 怎样捕捉键盘的输入,即判断键盘上的那个键按下(在线等待)
- 急!请教高手们关于存储过程锁表问题50分!!在线等!
- 100分求一个把图片写入Access数据库,然后读出来的方法,顶者有分.
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Drawing.Imaging;
using System.Drawing.Drawing2D;
using System.Data.OleDb;
using System.Web.Security;namespace ANJA.admin_login
{
/// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.TextBox password;
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator2;
protected System.Web.UI.WebControls.Button Button2;
protected System.Web.UI.WebControls.Image Image1;
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1;
protected System.Web.UI.HtmlControls.HtmlForm Form1;
protected System.Web.UI.WebControls.Label Message;
protected System.Web.UI.WebControls.TextBox adminname;
protected System.Web.UI.WebControls.TextBox getimage;
protected System.Web.UI.WebControls.RegularExpressionValidator chk_userid02;
protected System.Web.UI.WebControls.RegularExpressionValidator chk_userid03;
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator4;
config obj = new config();
OleDbCommand mycommand;
OleDbDataReader rs;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(!this.IsPostBack)
{
//图片验证码的代码
//建立位图对象
Bitmap newBitmap = new Bitmap(36,16,PixelFormat.Format32bppArgb);
//根据上面创建的位图对象创建绘图面
Graphics g = Graphics.FromImage(newBitmap);
//以指定的颜色填充矩形区
g.FillRectangle(new SolidBrush(Color.White), new Rectangle(0,0,38,19));
//创建字体对象
Font textFont = new Font("Times New Roman",10);
//创建RectangleF结构指定一个区域
RectangleF rectangle = new RectangleF(0,0,38,19);
//创建随机数对象
Random rd = new Random();
//取得随机数
int valationNo = 1000 + rd.Next(8999);
//使用指定的颜色填充上面RectangleF结构指定的矩形区域
g.FillRectangle(new SolidBrush(Color.White), rectangle);
//在上面填充的矩形区域中填充上面生成的随机数
g.DrawString(valationNo.ToString(), textFont, new SolidBrush(Color.Red), rectangle);
//把创建的位图保存到指定的路径
newBitmap.Save(Server.MapPath("images")+"\\VaImg.gif", ImageFormat.Gif);
//图片验证码代码完毕 Session["getint"]=valationNo.ToString();
}
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Button2.Click += new System.EventHandler(this.Button2_Click);
this.Load += new System.EventHandler(this.Page_Load); }
#endregion private void Button1_Click(object sender, System.EventArgs e)
{
if(Page.IsValid)
{
if (getimage.Text.ToString().Trim() != Session["getint"].ToString())
{
Message.Text = "请输入正确有验证码!";
}
else
{
string a_userpassword = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(password.Text,"md5").ToLower();
obj.open();
mycommand=new OleDbCommand("select * from [admin] where adminname='"+ adminname.Text +"'",obj.myconn);
rs=mycommand.ExecuteReader();
if(!rs.Read())
{
obj.myconn.Close();
Message.Text = "只有相关人员才能进入,请确定你的身份!!";
return;
}
else
{
if(a_userpassword != rs["password"].ToString())
{
obj.myconn.Close();
Message.Text = "对不起,你输入有错误,如果一直出现这样的问题,请与管理员联系!!";
return;
}
else
{
Session["zmadmin"]=rs["adminname"].ToString();
Session["zmpwd"]=rs["password"].ToString();
Session["zmpopid"]=rs["popedom"].ToString();
obj.myconn.Close();
//Response.Write(Session["zmadmin"].ToString());
Response.Redirect("test.aspx");
}
rs.Close();
}
mycommand.Dispose();
obj.myconn.Close();
obj.myconn.Dispose();
}
}
} private void Button2_Click(object sender, System.EventArgs e)
{
adminname.Text="";
password.Text="";
getimage.Text=""; }
}
}
如果可以的话就是IE隐私被设置
Session.Timeout的时间是多少
private void Page_Load(object sender, System.EventArgs e)
{
Response.Write(Session["zmadmin"].ToString());
}
这样的结果如何
private void Page_Load(object sender, System.EventArgs e)
{
Response.Write(Session["zmadmin"].ToString());
}
未将对象引用设置到对象的实例。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。源错误:
行 21: private void Page_Load(object sender, System.EventArgs e)
行 22: {
行 23: Response.Write(Session["zmadmin"].ToString());
行 24: }
行 25:
怎么回事啊
<sessionState
mode="InProc"
stateConnectionString="tcpip=127.0.0.1:42424"
sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes"
cookieless="false"
timeout="20"
/>
这个也没问题啊
我把数据库放到BIN目录下面,从而导致Session和Application不断丢失