MVC3上redirecttoaction销毁会话 [英] MVC3 destroying session on redirecttoaction

查看:154
本文介绍了MVC3上redirecttoaction销毁会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有在MVC3应用程序会话的问题。在一个控制器我收到POST请求,然后重定向到控制器前增加值,以会话get方法。

问题是,在GET请求,即使在POST请求的会话值设置会话值返回null。

  [HttpPost]
公众的ActionResult是FindPerson(PersonSearch searchDetails)
{
    会话[FindPersons] = searchDetails;
    返回RedirectToAction(是FindPerson);
}
[HTTPGET]
公众的ActionResult是FindPerson()
{
    PersonSearch searchDetails =(PersonSearch)会议[FindPersons];


解决方案

解决方案:

在web.config中指定的会话状态cookie名称有些Nutter和认证形式的命名同样的事情。

 <的sessionState超时=20cookieName =间隔/><形式loginUrl =/隔离/登录NAME =垫片超时=2200/>

显然,它是一种具有正试图存储会话和饼干所谓殊途同归的效果。林很惊讶这只是没有爆炸。

感谢您的帮助@dknaack,我不会这么快,如果你不指着我正确的方向看准了这一点。

I have an issue with sessions in an MVC3 application. In one controller I am receiving a post request then adding the value to session before redirecting to the controllers get method.

The issue is that in the GET request the session value returns null even though in the POST request the sessions value was set.

[HttpPost]
public ActionResult findPerson(PersonSearch searchDetails)
{
    Session["FindPersons"] = searchDetails;
    return RedirectToAction("findperson");
}


[HttpGet]
public ActionResult findperson()
{
    PersonSearch searchDetails = (PersonSearch)Session["FindPersons"];

解决方案

Solution:

Some nutter named the session state cookie name in the web.config and the authentication forms name the same thing.

<sessionState timeout="20" cookieName="Spacer" />

<forms loginUrl="/spacer/login" name="Spacer" timeout="2200" />

Obviously the effect it was having was trying to store session and cookies in something called the same thing. Im very surprised this just did not blow up.

Thanks for your help @dknaack, I wouldnt have spotted this so quickly if you were not pointing me in the correct direction.

这篇关于MVC3上redirecttoaction销毁会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆