TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
kennedy_kevin
NA
1
0
Problem accessing cookie from C# code file.
Feb 21 2004 5:50 PM
Hi, This question may seem a little pedestrian to most of you but its got me stuck. I am developing a web application with several webforms. In each webform I have a function that checks a cookie for a value. This all seems to work fine OK. However I've just tried to get organised and start reusing code so I created a code file (value.cs) with a new class and added the function that checks ths cookie value and declared the class in one of the webforms (webform1.aspx.cs). I can successfully call the function in the new class from the webform however the function that checks the cookie value, does not return the cookie value. Instead it throws the following exception: System.Web.HttpException: Request is not available in this context at System.Web.UI.Page.get_Request() in value.cs I can't help but think I am missing something blaringly obvious. Any help and suggestions are utterly welcomed!! Thanks! K2 Here is the code file: value.cs ---------------------------------------------------------------------- using System; using System.Collections; using System.ComponentModel; using System.Web.SessionState; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; namespace Test { public class valueCheck : System.Web.UI.Page { public int cookieValue = 0; public int getCookieValue() { try { cookieValue = int.Parse(Request.Cookies["testcookie"].Value.ToString()); } catch { cookieValue = 0; } return cookieValue; } } } -------------------------------------------------------------------------- Here is the webform code: webform1.aspx.cs using System; using System.Collections; using System.ComponentModel; using System.Web.SessionState; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; namespace Test { public class home : System.Web.UI.Page { private void Page_Load(object sender, System.EventArgs e) { int currentValue = 0; valueCheck myCookieValue = new valueCheck(); currentValue = myCookieValue.getCookieValue(); } } }
Reply
Answers (
0
)
beginner needs help
Working Images on Pocket PC