HI mọi người mình sửu dụng ngôn ngữ asp.net lập trình web, khi tạo file ashx mình gọi Session trong file ashx thì giá trị trả về null không thấy dù đã khai báo.từ khi mở web như dưới. Mã: //khai báo trong Global.asax void Session_Start(object sender, EventArgs e) { DataTable GioHang = new DataTable(); GioHang.Columns.Add("ProductID", typeof(string)); GioHang.Columns.Add("ProductNameShort", typeof(string)); GioHang.Columns.Add("GiaSP", typeof(float)); GioHang.Columns.Add("GiaSPCu", typeof(float)); GioHang.Columns.Add("imgUrl", typeof(string)); GioHang.Columns.Add("SoLuong", typeof(int)); GioHang.Columns.Add("ThanhTien", typeof(float), "GiaSP*SoLuong"); GioHang.PrimaryKey = new DataColumn[] { GioHang.Columns["ProductID"] }; Session["GioHang"] = GioHang; } Mã: //khai báo trong ProductByCart.ashx public class ProductByCart : IHttpHandler { public void ProcessRequest(HttpContext context) { DataTable GioHang = (DataTable)context.Session["GioHang"]; ..... } } Giá trị trả về context.Session["GioHang"] = null Dữ liệu mình lấy lại không có, dù mình đã tạo mới ngay từ lúc mở web hizz. ai biết giúp với.
Bạn phải khai báo thêm dữ liệu nhận biết Session trong file ashx là : IReadOnlySessionState và dùng thư viện using System.Web.SessionState; Ví dụ như code của bạn mình chỉnh lại sau: Mã: //khai báo trong ProductByCart.ashx using System.Web.SessionState; public class ProductByCart : IHttpHandler, IReadOnlySessionState { public void ProcessRequest(HttpContext context) { DataTable GioHang = (DataTable)context.Session["GioHang"]; ..... } } Bạn làm giống vậy và kiểm tra lại nhé. Dữ liệu sẽ có khi bạn làm như trên.
Vị huynh đài này khẩu ngôn vô cùng sắc bén… kiến thức uyên thâm.. lời nói nặng tựa ngàn cân, như ngàn đao vạn kiếm tung hoành bốn phương khiến các anhhùng hào kiệt chỉ nhìn qua di động thôi e rằng đã đủ khiếp sợ!!!