ASP.NET 配置文件版本控制?

发布于 2024-09-14 03:31:03 字数 201 浏览 2 评论 0原文

ASP.NET 配置文件如何处理版本控制?我知道因为数据是序列化的,这可能是一个问题,而表则不是。

它会抛出某种序列化错误吗?

示例:我将 v1 对象存储到配置文件中。我使用新的 v2 版本更新了我的 Web 应用程序,但数据库仍然包含 v1 对象。

当我尝试将 v1 对象反序列化为 v2 对象时会发生什么?这个问题的最佳解决方案是什么?

How does ASP.NET profiles handle versioning? I know because the data is serialized this could be a problem where with tables it is not.

Will it throw some sort of serialization error?

Example: I store a v1 object to the profiles. I update my web application with a new v2 version but the database still contains v1 objects.

What will happen when I attempt to deserialize the v1 objects into the v2 objects? And what are the best solutions for this problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

入怼 2024-09-21 03:31:03

通常,ASP.NET 将配置文件数据视为属性包 - 因此它可能会跳过某个属性(已存储在数据存储中)但从配置中删除。同样,对于新添加的属性,它将使用默认值。现在,属性的类型也很重要 - 如果属性类型是您的自定义类,那么其序列化将由 XmlSerializer 或 BinaryFormatter 处理。 XmlSerializer 是默认值,通常是一个宽容的序列化器(缺少的属性将被跳过等)。您可以使用属性来控制 xml 序列化。对于 BinaryFormatter,它与运行时序列化相同,如果您希望支持版本控制,最好实现 ISerialized 并处理任何版本控制问题。我不确定如果您拥有某种类型 A 的配置文件属性,然后删除该类型,会发生什么情况。我的猜测是你应该得到一个错误,但我不确定这一点。

我通常更喜欢汇总自己的实现来支持用户配置文件功能,因为

  1. 可以根据我的喜好控制版本控制等内容
  2. 选择存储和存储模式
    可以是独立的(这是可能的
    通过自定义在 ASP.NET 配置文件中
    配置文件提供者)
  3. 它可以很容易地放入
    分层应用程序和配置文件数据
    也可用于任何非网络
    如果需要的话,客户
  4. 尽管这意味着重新发明
    轮子并付出一些额外的努力,
    对于任何具有以下功能的软件来说,它的价值
    保质期2-3年以上。
  5. 我可以精确控制何时
    存储/检索配置文件数据
    数据存储。

Typically ASP.NET treats profile data as a property bag - so it would probably skip a property (that has been stored in data store) but deleted from configuration. Similarly, for newly added property, it would use the default value. Now, type of properties will also matter - if property type is your custom class then its serialization will be handled by either XmlSerializer or BinaryFormatter. XmlSerializer is a default and its generally a tolerant serializer (missing properties will be skipped etc). You can use attributes to control xml serialization. In case of BinaryFormatter, its same as runtime serialization and if you wish to support versioning, its best that you implement ISerializable and handle any versioning issues. I am not certain what would happen in a case where you have a profile property of some type A and then you delete that type. My guess is that you should get an error but I am not ceratin about it.

I typically prefer to roll up my own implementation for supporting user profile feature because

  1. Things such as versioning etc can be controlled as per my liking
  2. Choice of store and storage schema
    can be independent (this is possible
    in ASP.NET profiles by custom
    profile provider)
  3. It can be easily put into the
    layered application and profile data
    is also available to any non-web
    clients if needed
  4. Although it means re-inventing the
    wheel and having some extra effort,
    its worth for any software that has
    shelf life of more than 2-3 years.
  5. I can control precisely when to
    store/retrieve the profile data from
    the data store.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文