简体   繁体   English

将基于会话的asp.net应用程序移至n层体系结构

[英]Moving a session based asp.net application to an n-tiered architecture

I've inherited a large asp.net website that relies heavily on session information. 我继承了一个很大的asp.net网站,该网站严重依赖会话信息。

There is a back-end system that feeds it necessary information as needed through web services, but the application itself has no database, and everything is kept in session through a bunch of Data Objects which are accessed directly throughout the entire application. 有一个后端系统,可以通过Web服务根据需要向其提供必要的信息,但是应用程序本身没有数据库,所有内容都通过一堆数据对象保持在会话中,这些数据对象可在整个应用程序中直接访问。

I eventually want to try to migrate the application to a true N-Tier architecture, and start using a database instead of session based data objects. 我最终希望尝试将应用程序迁移到真正的N层体系结构,并开始使用数据库而不是基于会话的数据对象。

My question is, what is a recommended path to get to the desired architecture? 我的问题是,到达所需架构的推荐路径是什么?

I'm thinking that an initial step would be to create a Data Access Layer for accessing the data objects. 我认为第一步将是创建用于访问数据对象的数据访问层。 Once this is in place, I would then be able to replace the data objects with a database. 一旦到位,我便可以用数据库替换数据对象。

The problem is that the session Data Objects are directly accessed from everywhere in the application. 问题在于,可以从应用程序中的任何位置直接访问会话数据对象。 Because these objects are stored in session, you can directly set any of their properties without anything controlling the data. 由于这些对象存储在会话中,因此您可以直接设置它们的任何属性,而无需任何控制数据的操作。 This is done throughout the whole application. 这是在整个应用程序中完成的。

For example, say you have a customer Data Object stored in session. 例如,假设您有一个存储在会话中的客户数据对象。 If you wanted to modify this customer, all you have to do is to set a local variable to the object stored in session. 如果要修改此客户,您要做的就是将本地变量设置为存储在会话中的对象。 You could then update anything in the object just by setting mylocalvar.LastName = "blah"; 然后,只需设置mylocalvar.LastName =“ blah”;即可更新对象中的所有内容 Your session object is now updated without doing anything else. 现在,您的会话对象已更新,无需执行任何其他操作。

Has anyone done anything like this before, and has any ideas on steps I could use to accomplish it? 以前有没有人做过这样的事情,并且对我可以用来完成它的步骤有任何想法?

*note: I'm not looking to off-load the session data, but to re-architect how the data is saved and accessed. *注意:我不是要卸载会话数据,而是要重新设计如何保存和访问数据。

Sounds like a big job! 听起来是一项艰巨的任务!

I guess the first step is to build an abstraction layer for your session information and refactor your code so that it depends on that instead of the session. 我想第一步是为您的会话信息构建一个抽象层,并重构代码,使其依赖于该会话而不是会话。 Once you've done that, with your gui code now dependant only on the abstraction layer, you'll be able to pull out the session code out of the abstraction layer and replace it with data access code and your gui should be none the wiser. 完成此操作后,您的gui代码现在仅依赖于抽象层,您将能够从抽象层中提取会话代码,并用数据访问代码替换它,而gui应该不是更明智的选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM