当前位置:编程学习 > C#/ASP.NET >>

关于session的问题

我在login.cs文件里设置了一个session,代码如下:

Session["username"] = username;(比方说,我现在username是“yafee”)

现在我想在default.ashx一般处理程序里面接收这个Session["username"],该怎么办?

用context.session["username"].toString(),不行

该用什么方法接收呢??? --------------------编程问答-------------------- Index页面:

 protected void Button1_Click(object sender, EventArgs e)
        {
            try
            {
                
                Session["username"] = "rodickeeeeeeeeee";
                Response.Redirect("Home.aspx");

            }
            catch
            { 
             
            }
        }



Home.aspx页面:

protected void Page_Load(object sender, EventArgs e)
        {
            Response.Write(Session["username"].ToString());
        }

--------------------编程问答-------------------- using System.Web.SessionState;
public class login : IHttpHandler,IRequiresSessionState


HttpContext.Current.Session["user"] = xxxxx;

--------------------编程问答--------------------
引用 1 楼 ustbwuyi 的回复:
Index页面:
C# code

 protected void Button1_Click(object sender, EventArgs e)
        {
            try
            {
                
                Session["username"] = "rodickeeeeeeeeee";
      ……


如果我不Response.Redirect("Home.aspx"),那么在Home.aspx页面能不能接收到Session["username"]呢??

现在我想在.ashx一般处理程序页里面接收他,该怎么写呢???


谢谢!!! --------------------编程问答-------------------- 继承 IHttpHandler,IRequiresSessionState --------------------编程问答-------------------- 不要tostring()
直接session["user"] 就可以 --------------------编程问答--------------------
引用 4 楼 wxr0323 的回复:
继承 IHttpHandler,IRequiresSessionState


哪个页面继承 IHttpHandler,IRequiresSessionState啊?是ashx页还是设置session的cs页??? --------------------编程问答--------------------
引用 2 楼 itlizhi 的回复:
using System.Web.SessionState;
public class login : IHttpHandler,IRequiresSessionState


HttpContext.Current.Session["user"] = xxxxx;


是不是这样的啊
--------------------编程问答--------------------
引用 7 楼 yafelog 的回复:
引用 2 楼 itlizhi 的回复:

using System.Web.SessionState;
public class login : IHttpHandler,IRequiresSessionState


HttpContext.Current.Session["user"] = xxxxx;


是不是这样的啊

ashx页面 using一个 System.Web.SessionState;
继承IRequiresSessionState 接口 
在你需要用session 的ashx页面 都需要引用的 ,.cs是不需要的 --------------------编程问答--------------------
引用 8 楼 itlizhi 的回复:
引用 7 楼 yafelog 的回复:

引用 2 楼 itlizhi 的回复:

using System.Web.SessionState;
public class login : IHttpHandler,IRequiresSessionState


HttpContext.Current.Session["user"] = xxxxx;


是不是这样的啊

……



哦,谢谢,我搞定了,呵呵呵 --------------------编程问答-------------------- mark --------------------编程问答--------------------
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,