Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Any downsides to cookie assignment inside custom class using HttpContext.Current? ASP.NET 2.0 cookie fix?

Reply
Thread Tools

Any downsides to cookie assignment inside custom class using HttpContext.Current? ASP.NET 2.0 cookie fix?

 
 
Guest
Posts: n/a
 
      08-17-2005
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.



 
Reply With Quote
 
 
 
 
Karl Seguin
Guest
Posts: n/a
 
      08-17-2005
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!)


<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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.
>
>
>



 
Reply With Quote
 
 
 
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      08-17-2005
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: <(E-Mail Removed)>
| 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: <(E-Mail Removed)>
| 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!)
|
|
| <(E-Mail Removed)> wrote in message
| news:(E-Mail Removed)...
| > 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.
| >
| >
| >
|
|
|

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Downsides to leaving my home computer connected to VPN 24/7? Brad Isaac Cisco 2 02-05-2009 01:42 PM
Canon S5 IS - Any downsides to this updated platform? Paul D. Sullivan Digital Photography 17 05-10-2007 01:06 PM
501 PIX "deny any any" "allow any any" Any Anybody? Networking Student Cisco 4 11-16-2006 10:40 PM
Nested Class, Member Class, Inner Class, Local Class, Anonymous Class E11 Java 1 10-12-2005 03:34 PM
What are the downsides of using frames? tx, eom Dee ASP .Net 2 05-16-2005 12:29 AM



Advertisments