如何处理后重定向 - 获取NancyFx

时间:2014-08-10 20:06:02

标签: asp.net-mvc nancy

使用PRG模式我经常需要在重定向中传递数据。成功保存数据是最常见的。

在ASP.NET MVC中,TempData对象可以保存仅存在一个重定向/请求的数据。

我应该如何在NancyFx中处理这种情况?

1 个答案:

答案 0 :(得分:2)

根据建议,我最终使用session作为假临时数据。我创造了一个要点。 https://gist.github.com/detroitpro/4b2f7585d25ab37f2e59

 protected override void ApplicationStartup(IWindsorContainer container, IPipelines pipelines)
        {
            pipelines.BeforeRequest += (ctx) =>
            {
                if (ctx.Request.Session["TempMessage"] != null && !string.IsNullOrEmpty(ctx.Request.Session["TempMessage"] as string))
                {
                    ctx.ViewBag.TempMessage = ctx.Request.Session["TempMessage"];
                    ctx.ViewBag.TempType = ctx.Request.Session["TempType"];
                    ctx.Request.Session.DeleteAll();
                }
                return null;
            };
        }