【问题标题】:How to handle Post-Redirect-Get in NancyFx如何在 NancyFx 中处理 Post-Redirect-Get
【发布时间】:2016-04-29 04:07:54
【问题描述】:

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

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

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

【问题讨论】:

  • :(我希望人们停止使用 PGR 模式,停止向服务器发送无效请求,并且您不需要 PGR 模式。

标签: asp.net-mvc nancy


【解决方案1】:

根据我最终使用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;
            };
        }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-26
    • 2015-04-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多