Thanks for Karl's informative inputs.
Hi kenfine,
I think Karl's suggestions are quite reasonable. The behavior is just the
same no matter in asp.net 1.x or 2.x. Also, it's better that we guarantee
the component is used in asp.net web application only since the HttpContext
won't exists in other desktop or service app.
Thanks,
Steven Cheng
Microsoft Online Support
Get Secure!
www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| From: "Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME
net>
| References: <uI**************@TK2MSFTNGP10.phx.gbl>
| Subject: Re: Any downsides to cookie assignment inside custom class using
HttpContext.Current? ASP.NET 2.0 cookie fix?
| Date: Tue, 16 Aug 2005 22:53:15 -0400
| Lines: 38
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
| X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
| X-RFC2646: Format=Flowed; Response
| Message-ID: <OI**************@TK2MSFTNGP10.phx.gbl>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: 206-248-153-84.dsl.teksavvy.com 206.248.153.84
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP10.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet:118483
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| This is true in 1.x as well. Request/Response/... are available in
| codebehind 'cuz your class inherits from Control (via Page/UserControl)
| which exposes this properties. Your custom class, which doesn't inherit
| from such as base class doesn't have these things set up (and it
shouldn't).
| So you hook into the page framework via HttpContext.Current.
|
| Anyways, to get to your question, are there any downside? Well, you are
| tying your custom class to the web, but I can't say if that's a downside
or
| not in this situation. Do you ever plan on reusing this class inside a
dos
| console, web service or win form?HttpContext.Current will be null in
those
| situations, so HttpContext.Current.Response will throw a null reference
| exception. There's nothing wrong with building a this type of
dependency,
| but the class shouldn't be considered part of your business layer
| anymore...it is now part of your presentation layer.
|
| Karl
|
| --
| MY ASP.Net tutorials
|
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
|
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
| come!)
|
|
| <ke*****@nospam.nospam> wrote in message
| news:uI**************@TK2MSFTNGP10.phx.gbl...
| > Today I learned that creating cookies inside of a custom class in
ASP.NET
| > 2.0 requires that you prefix it with HttpContext.Current..., e.g. :
| >
| > HttpContext.Current.Response.Cookies.Add("myNewCoo kie");
| >
| > I am wondering if there are any landmines that I should know about, or
if
| > this will work pretty much as I am expecting a cookie should.
| >
| >
| >
|
|
|