.NET豆+请求范围 - 这可能吗?这可、范围、NET

2023-09-03 20:32:37 作者:苏姬

我有我的Web应用程序。我需要,当用户做一个请求(我的意思是,所说的页)创建存储一些信息的对象(它从数据库获得这些)为每个请求(这样的数据在每一个请求更新),并为每个用户(这样用户A不共享相同的对象方面,用户B)。

I have my web application. I need, when a user do a request (I mean, call a page) create an object that store some information (it get these from database) for each request (so the data is updated at every request) and for each user (so UserA don't share the same object regard UserB).

我用它来工作,Java和一些Web框架(如Struts,Spring和JSF),并有可能创建这些对象(JavaBeans的)与请求范围,并把它们可见整个应用程序。我的意思是:

I use to work on Java and some Web Frameworks (like Struts, Spring and JSF) and there was possible to create these objects (JavaBeans) with scope of request, and putting them visible for the whole application. I mean :

public class iContext
{
    public iContext()
    {
        Response.Write(myBeans.Title());
    }    
}

这是可能的,而不创建MyBeans的Istance每次。 我认为把对象的会话,但我preFEER摆脱这个(其实我应该检查,更换,删除或查询每一次和done吨插入对象:)。)

it's possible without create an Istance of MyBeans every time . I thought to put the object on session, but I prefeer to get rid about this (in fact I should check, replace, delete or insert the object every time and done tons of queries :)).

有没有一些策略做这种基于.NET 3.5和C#的工作?

Are there some strategies to do this kind of work on .NET 3.5 and C#?

推荐答案

在ASP.Net重要的是要了解页面的生命周期。如果你理解了这一点,你可以使用HttpContext.Items [] Dictionary对象,以填补在(pre)自定义上下文类页面的初始化阶段。任何你加载数据,这是重要的是保持在内存中,你可以将它添加到你的上下文类,你想,因为HttpContext的可在任何时候都在你的页面的范围,在任何地方使用它。

In ASP.Net it's important to know the page's life cycle. If you understand this, you could use the HttpContext.Items[] Dictionary object to fill with your custom context class in the (pre) init phase of the page. Anywhere you load data that's important to keep in memory you can add it to your context class and use it anywhere you want since HttpContext is available at all times in the scope of your page.