asp.net mvc2 中如何获得Session 我的是两个一般处理程序文件,A页面是生成验证码的ashx文件,B页面是用来ajax登录的ashx文件,但是在B页面中无法获得A页面储存的session。以前在使用asp.net的时候只是在获取Session的ashx文件中实现一个IReadOnlySessionState接口就可以了,但是在mvc中这样貌似不行。刚学mvc,忘各位大侠赐教。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 mvc里面 页面间传值用tempdata 刚好我的两个页面是用ashx,并且是使用ajax.请求的页面是html。但是在处理登录的ashx的页面就是找不到Session。mvc里面 页面间传值用tempdata。能说的具体点吗?mvc新手。 tempdata["name"]=value 但是用tempdate里面的数据只能取一次 或者20分钟 之后数据就销毁了 另外ashx可以通过httpcontext.current来获得session 取到的都是null,不知道怎么回事。 public JsonResult Ajax1() { this.HttpContext.Session["aaa"] = "aaa"; return Json(new { a="action"}); } public JsonResult Ajax2() { string s = this.HttpContext.Session["aaa"] as String; return Json(new { a="action"});; }$(document).ready(function () { $.ajax({ type: "post", url:"/Home/Ajax1", success:function(){ alert("1"); } }) }) function Send(){ $.ajax({ type:"post", url:"/Home/Ajax2", success:function(){ alert("2"); } }) }能取到session的值啊 LZ是怎么取到值的?我也一直都是NULL 生机随机数中的一句代码? 切字符串 网页自动打印问题 关于freetextbox ◆◆如何传递1组SQL参数◆并在存储过程中遍历?◆◆ ◆◆ 关于从aspx中获得ascx中的全局变量的问题 写web.config文件后 Session实效,有什么解决办法吗 web.config连接问题! 用C#访问Excle表中的数据 我刚接触asp.net有那位,大哥,大姐,给我讲一课啊!谢了! dataGridView操作完成后,如何将数据保留在当前页,而不更新至第一行? ajax
取到的都是null,不知道怎么回事。
public JsonResult Ajax1()
{
this.HttpContext.Session["aaa"] = "aaa";
return Json(new { a="action"});
} public JsonResult Ajax2()
{
string s = this.HttpContext.Session["aaa"] as String;
return Json(new { a="action"});;
}
$(document).ready(function () {
$.ajax({
type: "post",
url:"/Home/Ajax1",
success:function(){
alert("1");
}
})
})
function Send(){
$.ajax({
type:"post",
url:"/Home/Ajax2",
success:function(){
alert("2");
}
})
}能取到session的值啊