VoyForums
[ Show ]
Support VoyForums
[ Shrink ]
VoyForums Announcement: Programming and providing support for this service has been a labor of love since 1997. We are one of the few services online who values our users' privacy, and have never sold your information. We have even fought hard to defend your privacy in legal cases; however, we've done it with almost no financial support -- paying out of pocket to continue providing the service. Due to the issues imposed on us by advertisers, we also stopped hosting most ads on the forums many years ago. We hope you appreciate our efforts.

Show your support by donating any amount. (Note: We are still technically a for-profit company, so your contribution is not tax-deductible.) PayPal Acct: Feedback:

Donate to VoyForums (PayPal):

Login ] [ Contact Forum Admin ] [ Main index ] [ Post a new message ] [ Search | Check update time | Archives: [1] ]
Subject: ASP.Net cookies vs HttpContext (Context.Items.Add())


Author:
Jose Varghese
[ Next Thread | Previous Thread | Next Message | Previous Message ]
Date Posted: 02:51:41 05/20/05 Fri

ASP.Net Cookies Vs HttpContext

HttpContext is normally used when data is needed in memory only at the moment of page transfer. This is the state that lives in HttpContext.Items, which only lasts for the duration of the current request, hence its characteristic of "transient". It's quickly discarded as soon as the current request has finished processing, so it doesn't impose any of the drawbacks you need to care about with Session. So it is better to use HttpContext than cookies to store inter-page state. Cookies are a bad choice for storing state.

But HttpContext will only work in conjunction with Server.Transfer. It will not work using Response.Redirect. The reason why it will not work with Response.Redirect is because Redirect results in another round trip to the client which results in a new HTTP Request and thus a new HTTPContext.

As regards to size of data HttpContext does support more size than cookies. Currently each cookie is limited to a size of 4096 bytes. Context objects allows you the flexibility to pass any kind of object from simple text to heavy objects like dataset which one cant do with cookies. Infact most of the limitations of cookies don't apply to HttpContext.

As regards to performance HttpContext does not make any problem since the request last only for the duration of the current request i.e till the time the next page is loaded. After that the object is no longer accessible and eliminates the cleaning code required in next page like the way it is required in Session.

Adding Items to Context
-----------------------
Context.Items.Add("UserId", txtUserId.Text);

Retrieving Items from Context
-----------------------------
txtUserId.Text = Context.Items["UserId"];

[ Next Thread | Previous Thread | Next Message | Previous Message ]


[ Contact Forum Admin ]


Forum timezone: GMT-8
VF Version: 3.00b, ConfDB:
Before posting please read our privacy policy.
VoyForums(tm) is a Free Service from Voyager Info-Systems.
Copyright © 1998-2019 Voyager Info-Systems. All Rights Reserved.