Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cannot write Cookies in a C# class?!?

Status
Not open for further replies.

DLLHell

Programmer
May 9, 2003
69
US
I use a C# class to Fill a DataTable and return it. My problem is I have to do a Try...Catch in the event of errors but I can't send back the Exception Error string, only the DataTable can be sent back. I tried writing the exception error into a Cookie in the Class but it won't compile - it keeps rejecting the "Response" part of the code, and adding namespaces from where I have no problem writing cookies has not solved the compiler problem.

Any other options or ways to get around this problem? Thanks.

catch (Exception exc)
{
string strError = exc.ToString();
HttpCookie ErrorCookie = new HttpCookie("ErrorCookie");
ErrorCookie.Value = strError;
Response.Cookies.Add(ErrorCookie);
}
 
If you're doing this from within a class, you have to use response like this:

System.Web.HttpContext.Current.Response.Cookies.Add([foo]);

System.Web.HttpContext.Current also opens up Request, Session and other such objects for use from within a class.

-----------------------------------------------
"The night sky over the planet Krikkit is the least interesting sight in the entire universe."
-Hitch Hiker's Guide To The Galaxy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top