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

怎么在ashx一般处理程序里面接收session值



login.cs如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data.SqlClient;
using System.Data;
using System.Web.SessionState;

public partial class login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }
     //。。。省去无关代码
    protected void btn_login_Click(object sender, EventArgs e)
    {
        string username = Request.Form["username"];
        string password = Request.Form["password"];

        if (validation(username, password))
        {
            Session["username"] = username;
            Response.Redirect("Default.aspx");
        }
    }
}


现在我想在post_details.ashx里接受这个session["username"],该怎么办?????

<%@ WebHandler Language="C#" Class="postdetails" %>

using System;
using System.Web;
using System.Data.SqlClient;
using System.Data;

public class postdetails : IHttpHandler {
    
    public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "text/plain";

        string username=context.session["username"].toString();  //这种方法不行啊
    }



该怎么办呢???? --------------------编程问答-------------------- postdetails : IHttpHandler ,IRequiresSessionState --------------------编程问答-------------------- 如上所说。 --------------------编程问答-------------------- 恩  顶楼上 --------------------编程问答-------------------- 如上上上所说! --------------------编程问答--------------------
引用 1 楼 huangwenquan123 的回复:
postdetails : IHttpHandler ,IRequiresSessionState


要加它IRequiresSessionState --------------------编程问答-------------------- //ashx中利用Session保存信息必须加上接口: System.Web.SessionState.IRequiresSessionState --------------------编程问答--------------------
引用 1 楼 huangwenquan123 的回复:
postdetails : IHttpHandler ,IRequiresSessionState

正解.. :) --------------------编程问答-------------------- 在一般处理程序(.ashx)中实现Session,必须实现IRequiresSessionState接口,如1楼所说,然后再用context.session["username"]就可以了 --------------------编程问答-------------------- 楼上正解。 --------------------编程问答-------------------- 在一般处理程序(.ashx)中实现Session,必须实现IRequiresSessionState接口,如1楼所说,然后再用context.session["username"]就可以了

学习了。。。 --------------------编程问答-------------------- context.session[]
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,