Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx thread: Using Cookies in an Assembly


Message #1 by "Tom Cole" <tc@n...> on Tue, 28 May 2002 17:44:56
I get this error message when I am trying to use a cookie within an 
Assembly.

[HttpException (0x80004005): Response is not available in this context.]

 
How can I store a cookie from within an Assembly?
Message #2 by Feduke Cntr Charles R <FedukeCR@m...> on Tue, 28 May 2002 13:13:51 -0400
Tom,

	This is a total wild guess here, but try something like...

// include this namespace
using System.Web;

// in your code, where ever:
HttpRequest req = HttpContext.Current.Request;
string userName = (string)req.Cookies["username"];

	Let us know if that works.

- Chuck


-----Original Message-----
From: Tom Cole [mailto:tc@n...]
Sent: Tuesday, May 28, 2002 1:45 PM
To: ASP+
Subject: [aspx] Using Cookies in an Assembly


I get this error message when I am trying to use a cookie within an 
Assembly.

[HttpException (0x80004005): Response is not available in this context.]

 
How can I store a cookie from within an Assembly?
Message #3 by "Tom Cole" <tc@n...> on Wed, 29 May 2002 16:27:47
Thanks for turning me on to the HttpContext, Chuck

That did the trick.  Here's my test case.

Public Class Test

  Public Sub StoreCookie()
    Dim objResponse As HttpResponse
    objResponse = HttpContext.Current.Response
    Dim objCookie As HttpCookie = New HttpCookie("myCookie", "123456")
    objResponse.Cookies.Add(objCookie)
  End Sub

  Public Function GetCookie() As String
    Dim objRequest As HttpRequest
    objRequest = HttpContext.Current.Request
    Dim objCookie As HttpCookie
    objCookie = objRequest.Cookies.Get("myCookie")
    GetCookie = objCookie.Value
  End Function

End Class


> Tom,

	This is a total wild guess here, but try something like...

// include this namespace
using System.Web;

// in your code, where ever:
HttpRequest req = HttpContext.Current.Request;
string userName = (string)req.Cookies["username"];

	Let us know if that works.

- Chuck

  Return to Index