开发者

.NET Beans + request scope - is it possible?

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 开发者_StackOverflowat every request) and for each user (so UserA don't share the same object regard UserB).

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());
    }    
}

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 :)).

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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜