在ASP.NET MVC坚持回发之间复杂的数据 [英] Persisting complex data between postbacks in ASP.NET MVC

查看:122
本文介绍了在ASP.NET MVC坚持回发之间复杂的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发一个ASP.NET MVC 2应用程序连接到一些服务进行数据检索和更新。该服务要求我公司提供的原始的实体与实体的更新以及更新数据。这是为了它可以做变更跟踪和乐观并发。该服务无法更改。

I'm developing an ASP.NET MVC 2 application that connects to some services to do data retrieval and update. The services require that I provide the original entity along with the updated entity when updating data. This is so it can do change tracking and optimistic concurrency. The services cannot be changed.

我的问题是,我需要以某种方式保存回发之间原有的实体。在的WebForms,我会使用ViewState的,但是从我已阅读,这是出MVC。原始值不必是防篡改的服务将它们视为不受信任。该实体将是(最大值)1K,这是一个Intranet应用程序。

My problem is that I need to somehow store the original entity between postbacks. In WebForms, I would have used ViewState, but from what I have read, that is out for MVC. The original values do not have to be tamper proof as the services treat them as untrusted. The entities would be (max) 1k and it is an intranet app.

我想出的选项是:


  1. 会议 - 排除了 - 存储在会话实体,但由于目前还没有计划之间共享会话,我不喜欢这个主意

  2. 网址 - 排除了 - 数据量太大

  3. HiddenField - 存储序列化的实体在一个隐藏字段,或许与加密/编码

  4. HiddenVersion - 这些实体对他们有(SQL)版本领域,我可以放入一个隐藏字段。然后在一个救我从服务原始的实体和比较的版本,做我自己的乐观并发。

  5. 饼干 - 像3或4,但使用的cookie,而不是隐藏字段

  1. Session - Ruled out - Store the entity in the Session, but I don't like this idea as there are no plans to share session between
  2. URL - Ruled out - Data is too big
  3. HiddenField - Store the serialized entity in a hidden field, perhaps with encryption/encoding
  4. HiddenVersion - The entities have a (SQL) version field on them, which I could put into a hidden field. Then on a save I get "original" entity from the services and compare the versions, doing my own optimistic concurrency.
  5. Cookies - Like 3 or 4, but using a cookie instead of a hidden field

我倾向于选择4,虽然3会更简单。这些是有效的选项还是我下去在错误的轨道?是否有这样做的更好的办法?

I'm leaning towards option 4, although 3 would be simpler. Are these valid options or am I going down the wrong track? Is there a better way of doing this?

推荐答案

如果你做它保存在一个会话中,那么你需要确保你实施,本次会议是否正确装入一个Web农场。

If you do Store it in a session then you need to ensure that if you implement a web farm that the session is loaded correctly.

我们有(完全一致)同样的问题在这里的时刻,我们已经决定做的是落实Repository模式并将其链接到一个cookie。

We have (exactly) the same question here at the moment and what we've decided to do is to implement the Repository Pattern and link it to a cookie.

然后,如果这成为一个问题,我们可以简单地在任何一个会话管理器,数据库管理员或任何与我们的code插槽甚至不必知道,因为库格局。

Then, if this becomes an issue, we can simply slot in either a session manager, db manager or whatever and our code need not even know because of the repository pattern.

我们修修补补与隐藏字段的想法,但感觉太像ViewState中,我们都讨厌它的WebForms这样的想法被废弃了。但是,并非只是因为我们讨厌视图状态。有当你$ pssed Ctrl键F5 p $的问题。你是做什么的内容将被清除,然后呢?

We tinkered with the idea of hidden fields but it felt too much like ViewState and we all hated it in WebForms so the idea was scrapped. But not just because we hated view state. There were issues when you pressed Ctrl F5. The contents would be cleared and then what do you do?

因此​​,在这一点上它与一个cookie存储库的模式可能改变,但执行借自己好心来改变。

So at this point its a repository pattern with a cookie which may change but the implementation lends itself kindly to change.

修改

我们还针对隐藏字段决定,因为这将是很容易对其进行更改,所以你需要从服务器上做一些象征性的东西,以确保它wans't篡改。

We also decided against hidden fields because it would be too easy to make changes to them and so you need to do some token stuff from the server to ensure it wans't tampered with.

的隐藏字段只是不停地增加复杂什么本质上应该是一个非常简单的问题。

The hidden fields just kept on adding complexity to what essentially should have been a very simple problem.

至少这是我们对此事的看法。

At least that was our thoughts on the matter.

这篇关于在ASP.NET MVC坚持回发之间复杂的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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