TempData的/会话在MVC4 / IIS6没有返回存储的值 [英] TempData /Session in MVC4 / IIS6 not returning stored values
问题描述
与MVC / TempData的/会话/ IIS6可能类型的问题真的很挣扎。
Really struggling with an MVC / TempData / Session / possibly IIS6 type issue.
我有一个简单的MVC网站 - 主控制器是这样的:
I've got a simple MVC website - primary controller looks like this:
public class DemoController : Controller
{
[HttpPost]
public RedirectToRouteResult Index(SomeObject obj)
{
_someService.DoStuffWith(obj);
TempData.Add("SomeObject", obj);
return RedirectToAction("Index");
}
[HttpGet]
public ViewResult Index()
{
var obj = TempData.Peek("SomeObject") as SomeObject;
return View("Hello", obj);
}
}
因此,这是一个超级简单的POST重定向获取 - 从某处后友好的行动提交数据,得到它,做的东西有了它,戳它变成临时数据,重定向到获取友好,再次把它捡起来,粘用户与模型中的对象的新视图。已经实施了这样的前十次,从未有过的问题,但它一直在IIS7。
So this is a mega-simple Post Redirect Get - submit data from somewhere, get it in the Post-friendly action, do stuff with it, poke it into temp data, redirect to Get-friendly, pick it up again, stick the user on a new view with the object in the model. Have implemented this a dozen times before, and never had a problem, but it's always been on IIS7.
这在本地运行时的工作原理完全如预期,无论在卡西尼号,并在本地IIS 7.5。然而,当我部署到Server 2003和IIS6,我第一次尝试访问该视图中的SomeObject模式的任何财产,我得到一个空引用异常。
This works exactly as expected when running locally, both on cassini, and on local IIS 7.5. However, as soon as I deploy to Server 2003 and IIS6, the first time I try to access any property of the "SomeObject" model in the view, I get a null reference exception.
那么,什么人有我尝试:
So, what else have I tried:
- 我抛弃TempData的,只是推到会话[不管] - 以相同的结果
- 我推入HttpContext.Current.Session [不管] - 以相同的结果
- 我推入ControllerContext.HttpContext.Session [不管] - 以相同的结果
(诚然,我在这之间的差别粗略 - 从未需要之前我们担心它)
(Admittedly, i'm sketchy on the differences between these - have never needed to worry about it before now)
- 我做了一定的会话状态切换上IIS。
- 我已经签了Asp.net会话标识符不请求之间变化。
- 我已经部署了2个独立的服务器,都运行2003和IIS6,两个 相同的结果
- 明确地使用SessionStateBehaviour.Required
我不能够做什么:
- 部署到IIS7,我的本地机器外
- 使用SqlServer的SessionState会
- 使用的StateServer SessionState会
另外值得一提的是,这个网站使用的是MVC4 RC - 尽管RC功能并不在网站的这一特定部分使用
Also worth mentioning that this site is using the MVC4 RC - though the RC features are not used in this particular section of the site.
任何意见或建议,非常欢迎!
Any ideas or comments are most welcome!
感谢。
推荐答案
这是我的系统上的问题 - 我有下划线包含一个服务器名称。底线不是由RFC 952中的主机名不允许的,可能与设置Cookie,从而持续会话的能力。
This was the problem on my system - I had a server name that contained underscores. Underscores are not allowed in host names by RFC 952 and may interfere with the ability to set cookies and thus to persist sessions.
要跟踪此下来,我开始看的SessionID每个控制器部分,并注意到,与每一个岗位它是不断变化的。这只是发生我们的测试服务器上,因为我们与_t命名它显示它是一个试验机。哎哟!
To track this down I started watching the SessionID in each controller section and noticed that with every post it was changing. This was only happening on our test server because we named it with _t to show it was a test machine. OUCH!
我发现<一个href=\"http://weblogs.asp.net/bleroy/archive/2004/08/03/Don_2700_t-redirect-after-setting-a-Session-variable-_2800_or-do-it-right_2900_.aspx\"相对=nofollow>这一点。
这可能提供其他价值。
我希望这有助于
大卫
这篇关于TempData的/会话在MVC4 / IIS6没有返回存储的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!