C# getting cookie data in the preinit event
I have been seeing alot of code examples online of retrieving cookie data during the preinit event, but i don't understand wh开发者_如何学编程y you would want/have to do it there. Is it a steadfast rule that you should also be getting the cookie data in the preinit event?
You certainly don't have to get the cookie data in the preinit event, but it helps in two ways:
- You minimize the potential of cookies getting modified in later events during the page life cycle.
- If you are trying to affect things in the control tree using values read from a cookie, then you need to get that value during pre-init to ensure those values have a chance to do their job. Otherwise it would be too late and control collection will have already been built.
If you don't need those values to affect your page structure, or control flow, then you can read them whenever you want. It just happens to be that most people use cookies to change things early in the page life cycle so they read it during PreInit.
精彩评论