如何在ashx文件中使用Session

合法勒索夫斯基 2008-03-06 09:49:20
怎样才能在一般处理文件中创建新的Session和访问已经存在的Session?急~!
...全文
5909 18 打赏 收藏 转发到动态 举报
写回复
用AI写文章
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
schame 2011-05-16
  • 打赏
  • 举报
回复
[Quote=引用 16 楼 blackfield 的回复:]

//设置Session
System.Web.HttpContext.Current.Session["mySession"]="myString";
//获取Session
string myString=System.Web.HttpContext.Current.Session["mySession"]
[/Quote]

  • 打赏
  • 举报
回复
谢谢各位热情帮助~~但因为最近比较忙,还没来得及看,给分也比较仓促~~下次再多给点!
再次谢谢各位了!
blackField 2008-03-24
  • 打赏
  • 举报
回复
//设置Session
System.Web.HttpContext.Current.Session["mySession"]="myString";
//获取Session
string myString=System.Web.HttpContext.Current.Session["mySession"]
7仔 2008-03-24
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 WO_YOU_XIE_SHANG_XIN 的回复:]
唉 又错了 急个啥

C# codepublic class StatType : IHttpHandler, IRequiresSessionState
{
public void ProcessRequest (HttpContext context)
{
string s=context.Session["myString"]!=null?(string)context.Session["myString"]:"NoString";
}
}
[/Quote]
如果要对session有读写的操作,继承IRequiresSessionState
如果是只读 ,也可以继承IReadOnlySessionState 接口

liubiqu 2008-03-24
  • 打赏
  • 举报
回复
[Ajax.AjaxMethod(Ajax.HttpSessionStateRequirement.ReadWrite)]
public void Test5(string value)
{
HttpContext.Current.Session["test"] = value;
}

[Ajax.AjaxMethod(Ajax.HttpSessionStateRequirement.Read)]
public string Test6()
{
if(HttpContext.Current.Session["test"] != null)
return (string)HttpContext.Current.Session["test"];

return "First set the value...";
}
Magic_YJL 2008-03-24
  • 打赏
  • 举报
回复
哪位仁兄帮我个忙啊,非病毒,是俺的帖子
http://topic.csdn.net/u/20080324/09/d38253dc-c687-4c64-9381-3c66168c1b60.html
vc_delphi 2008-03-24
  • 打赏
  • 举报
回复
HttpContext.Current.Session

这样写与aspx页面写Session的效果是一样的
小伙写代码 2008-03-24
  • 打赏
  • 举报
回复
Handler.ashx 具体是用在什么地方的?
forverlove 2008-03-24
  • 打赏
  • 举报
回复
学习
drummery 2008-03-10
  • 打赏
  • 举报
回复
IRequiresSessionState,学习了
qq22345111 2008-03-07
  • 打赏
  • 举报
回复
炎 之 脉
方法通过!
地下室小红叔 2008-03-07
  • 打赏
  • 举报
回复
唉 又错了 急个啥
public class StatType : IHttpHandler, IRequiresSessionState 
{
public void ProcessRequest (HttpContext context)
{
string s=context.Session["myString"]!=null?(string)context.Session["myString"]:"NoString";
}
}
地下室小红叔 2008-03-07
  • 打赏
  • 举报
回复
不好意思手误 改改
public class StatType : IHttpHandler, IRequiresSessionState 
{
public void ProcessRequest (HttpContext context)
{
string s=context.Session["myString"]==null?(string)context.Session["myString"]:"NoString";
}
}
drummery 2008-03-07
  • 打赏
  • 举报
回复

HttpContext.Current.Session

Just try this.
地下室小红叔 2008-03-07
  • 打赏
  • 举报
回复
这样
public class StatType : IHttpHandler, IRequiresSessionState
{
public void ProcessRequest (HttpContext context)
{
string s=context.Session["myString"];
}
}
活靶子哥哥 2008-03-07
  • 打赏
  • 举报
回复
需要 你的 HttpHander 内实现 IRequiresSessionState 接口
wapit 2008-03-06
  • 打赏
  • 举报
回复
ashx? 新东东?
octverve 2008-03-06
  • 打赏
  • 举报
回复
ashx文件要使用Session,必须实现Session接口;
using System;
using System.Web;
using System.Web.SessionState; //第一步:导入此命名空间

public class checkCookie : IHttpHandler ,IRequiresSessionState //第二步:实现接口 到此就可以像平时一样用Session了
{

public void ProcessRequest (HttpContext context)
{

62,041

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧