Advertisement

01.18.2005 at 01:38PM PST, ID: 21279332
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

c#.net cookies & session varilabes

Zone: .NET
Tags: session, cookies
I normaly have always used session variables just becuase they are esier for me to set and retrive and never had more then two or three.....well session variables have become very unrealiable froceing me to use cookies.   I have no idea what the heck the proplem is here.  It keeps giveing my object not set error but i'm sure i have set the cookies.

Default home page:

if (UserTB.Rows.Count > 0)
                        {
                              HttpCookie cook = new HttpCookie("UserInfo");
                              cook.Values.Add("UserRole",UserTB.Rows[0]["Role"].ToString());
                              cook.Values.Add("LOBID", UserTB.Rows[0]["LOBID"].ToString());
                              cook.Values.Add("UserID", UserTB.Rows[0]["RecID"].ToString());
//Response.Cookies.Add(cook);
                              Response.AppendCookie(cook);
//      HttpCookie = new HttpCookie("LOBID", UserTB.Rows[0]["LOBID"].ToString());
//      HttpCookie = new HttpCookie("UserID", UserTB.Rows[0]["RecID"].ToString());
      
                        }

I think click leaveing the default page and going to another where i call the cookie

Response.Write(Request.Cookies["UserRole"].Values["LOBID"].ToString() + "<br>");
Response.Write(Request.Cookies["UserRole"].Values["UserID"].ToString() + "<br>");
Response.Write(Request.Cookies["UserRole"].Values["UserRole"].ToString() + "<br>");


why...won't...this...work...please help
Start your free trial to view this solution
Question Stats
Zone: Programming
Question Asked By: j_tipps
Solution Provided By: gsiric
Participating Experts: 1
Solution Grade: B
Views: 382
Translate:
Loading Advertisement...
01.18.2005 at 01:52PM PST, ID: 13077146

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
01.18.2005 at 02:08PM PST, ID: 13077349

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
01.18.2005 at 02:16PM PST, ID: 13077458

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
01.18.2005 at 02:20PM PST, ID: 13077499

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
01.18.2005 at 02:25PM PST, ID: 13077550

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
01.18.2005 at 02:34PM PST, ID: 13077635

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
01.18.2005 at 02:46PM PST, ID: 13077734

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
01.18.2005 at 02:54PM PST, ID: 13077824

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
01.18.2005 at 02:59PM PST, ID: 13077871

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
01.18.2005 at 03:01PM PST, ID: 13077882

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
01.18.2005 at 03:04PM PST, ID: 13077911

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
01.18.2005 at 03:07PM PST, ID: 13077946

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
01.18.2005 at 03:08PM PST, ID: 13077956

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
01.18.2005 at 03:24PM PST, ID: 13078106

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
01.18.2005 at 06:10PM PST, ID: 13079047

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
Microsoft
  • Internet Protocols
  • Applications
  • Development
  • OS
  • Hardware
  • Windows Security
Apple
  • Operating Systems
  • Hardware
  • Programming
  • Networking
  • Software
Internet
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Spy / Ad Blockers
  • Web Browsers
  • New Net Users
  • Web Development
  • Chat / IM
  • Anti Spam
  • Web Servers
  • Anti-Virus
  • Email Clients
Gamers
  • Tips
  • Online / MMORPG
  • Puzzle
  • Emulators
  • Action / Adventure
  • Role Playing
  • Consoles
  • Game Programming
  • Strategy
  • Sports
  • Misc
  • Computer Games
Digital Living
  • Hardware
  • New Net Users
  • New Users
  • Software
  • Digital Music
  • Gaming World
  • Home Security
  • Apple
  • Networking Hardware
Virus & Spyware
  • Vulnerabilities
  • IDS
  • Encryption
  • Anti-Virus
  • Operating Systems Security
  • Software Firewalls
  • WebApplications
  • Cell Phones
  • Operating Systems
  • Internet
  • Hardware Firewalls
Hardware
  • Handhelds / PDAs
  • Displays / Monitors
  • Components
  • Networking Hardware
  • Peripherals
  • Laptops/Notebooks
  • Storage
  • Servers
  • Desktops
  • New Users
  • Misc
  • Apple
Software
  • System Utilities
  • Industry Specific
  • Network Management
  • Photos / Graphics
  • Page Layout
  • VMWare
  • Misc
  • Web Development
  • OS
  • CYGWIN
  • Voice Recognition
  • Message Queue
  • Quality Assurance
  • Security
  • Firewalls
  • MultiMedia Applications
  • Development
  • Database
  • Office / Productivity
  • Business Management
  • OS/2 Apps
  • Server Software
  • Internet / Email
ITPro
  • OS
  • Storage
  • Encryption
  • Operating Systems Security
  • Apple Hardware
  • Laptops & Notebooks
  • Servers
  • Networking Hardware
  • Peripherals
  • Devices
  • Displays / Monitors
  • WebTrends / Stats
  • Search Engines
  • Firewalls
  • WebApplications
  • IDS
  • Vulnerabilities
  • Email Clients
  • File Sharing
  • Spy / Ad Blockers
  • Web Browsers
  • Web Servers
  • Networking
  • Anti-Virus
  • Chat / IM
  • Anti Spam
Developer
  • Web Servers
  • Web Browsers
  • Game Programming
  • Dev Tools
  • Industry Specific
  • Office / Productivity
  • Database
  • CYGWIN
  • Web Development
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Programming
  • Content Management
  • Application Servers
  • Protocols
Storage
  • Removable Backup Media
  • Storage Technology
  • Servers
  • Grid
  • Remote Access
  • Backup / Restore
  • Misc
  • Hard Drives
OS
  • Miscellaneous
  • Security
  • Development
  • Linux
  • VMWare
  • MainFrame OS
  • Unix
  • Apple
  • OS / 2
  • AS / 400
  • BeOS
  • Microsoft
  • VMS / OpenVMS
Database
  • Oracle
  • Miscellaneous
  • MySQL
  • Software
  • Sybase
  • Contact Management
  • PostgreSQL
  • Data Manipulation
  • Clarion
  • InterSystems Cache
  • Siebel
  • MUMPS
  • OLAP
  • SQLBase
  • SAS
  • GIS & GPS
  • 4GL
  • Berkeley DB
  • DB2
  • Informix
  • Interbase / Firebird
  • FoxPro
  • Reporting
  • LDAP
  • Filemaker Pro
  • MS SQL Server
  • dBase
  • MS Access
Security
  • Misc
  • Web Browsers
  • Software Firewalls
  • Operating Systems Security
  • File Sharing
  • Spy / Ad Blockers
  • Vulnerabilities
  • WebApplications
  • IDS
  • Anti-Virus
  • Encryption
  • Anti Spam
  • Email Clients
  • VPN
  • Chat / IM
Programming
  • Editors IDEs
  • Installation
  • Handhelds / PDAs
  • Multimedia Programming
  • System / Kernel
  • Algorithms
  • Game
  • Signal Processing
  • Project Management
  • Open Source
  • Database
  • Misc
  • Languages
  • Processor Platforms
  • Theory
Web Development
  • Scripting
  • Blogs
  • Web Servers
  • Software
  • Search Engines
  • Web Graphics
  • Images
  • Internet Marketing
  • Images and Photos
  • Components
  • Document Imaging
  • Web Languages/Standards
  • Illustration
  • WebApplications
  • Fonts
  • WebTrends / Stats
  • Authoring
  • Digital Camera Software
  • Miscellaneous
Networking
  • Protocols
  • Apple Networking
  • Network Management
  • Message Queue
  • Application Servers
  • Content Management
  • File Servers
  • Email Servers
  • Misc
  • Java Editors & IDEs
  • Wireless
  • Networking Hardware
  • Backup / Restore
  • System Utilities
  • ISPs & Hosting
  • Web Servers
  • Storage Technology
  • Removable Backup Media
  • Servers
  • Broadband
  • Grid
  • OS / 2
  • Novell Netware
  • Unix Networking
  • Windows Networking
  • Security
  • Telecommunications
  • Operating Systems
  • Linux Networking
Other
  • Community Advisor
  • Lounge
  • Community Support
  • New Net Users
  • Philosophy / Religion
  • Math / Science
  • Miscellaneous
  • URLs
  • Expert Lounge
  • Politics
  • Puzzles / Riddles
Community Support
  • Suggestions
  • New to EE
  • New Topics
  • Community Advisor
  • CleanUp
  • Announcements
  • General
  • Feedback
  • Input
  • EE Bugs
 
01.18.2005 at 01:52PM PST, ID: 13077146
sorry guys
i changed
Response.Write(Request.Cookies["UserRole"].Values["LOBID"].ToString() + "<br>");
Response.Write(Request.Cookies["UserRole"].Values["UserID"].ToString() + "<br>");
Response.Write(Request.Cookies["UserRole"].Values["UserRole"].ToString() + "<br>");

Too:
 Response.Write(Request.Cookies["UserInfo"].Values["LOBID"].ToString() + "<br>");
Response.Write(Request.Cookies["UserInfo"].Values["UserID"].ToString() + "<br>");
Response.Write(Request.Cookies["UserInfo"].Values["UserRole"].ToString() + "<br>");

I think i need to take a break haha
ok so code again is this and its give object not set

Default home page:

if (UserTB.Rows.Count > 0)
                    {
                         HttpCookie cook = new HttpCookie("UserInfo");
                         cook.Values.Add("UserRole",UserTB.Rows[0]["Role"].ToString());
                         cook.Values.Add("LOBID", UserTB.Rows[0]["LOBID"].ToString());
                         cook.Values.Add("UserID", UserTB.Rows[0]["RecID"].ToString());
//Response.Cookies.Add(cook);
                         Response.AppendCookie(cook);
//     HttpCookie = new HttpCookie("LOBID", UserTB.Rows[0]["LOBID"].ToString());
//     HttpCookie = new HttpCookie("UserID", UserTB.Rows[0]["RecID"].ToString());
     
                    }

I then click leaveing the default page and going to another where i call the cookie

 Response.Write(Request.Cookies["UserInfo"].Values["LOBID"].ToString() + "<br>");
Response.Write(Request.Cookies["UserInfo"].Values["UserID"].ToString() + "<br>");
Response.Write(Request.Cookies["UserInfo"].Values["UserRole"].ToString() + "<br>");
 
01.18.2005 at 02:08PM PST, ID: 13077349

Rank: Master

Try to define when cookie expires:
cook.Expires = DateTime.Now + TimeSpan.FromDays(1);


If you want to remove cookie set expires time in past:
cook.Expires = DateTime.Now - TimeSpan.FromDays(1);





 
01.18.2005 at 02:16PM PST, ID: 13077458
Added the code just cus it's a good idea, thank for the sujestion but still same error
The cookie is in being created, i checked the physical file
 
01.18.2005 at 02:20PM PST, ID: 13077499

Rank: Master

From MSDN:
AppendCookie: This member supports the .NET Framework infrastructure and is not intended to be used directly from your code

Try to use:
Response.Cookies.Add(cook);
 
01.18.2005 at 02:25PM PST, ID: 13077550
Thats what i had at first but i un-remed that line and tryed it again and same error
i can see the cookie in my temp directory.
COOKIE TEXT INFO:
UserInfo
UserRole=1&LOBID=1&UserID=21
inhousedev/
1024
1762154752
29687413
1083841248
29687212
*
 
01.18.2005 at 02:34PM PST, ID: 13077635

Rank: Master

So cookie is sent. Where in your code you want to obtain cookie ?
You need to set breakpoints and see which object is null.
Response, request  or cookie ?

try this:
if (Response == null)
{
  System.Diagnostic.Trace.WriteLine("Response is null");
  return;
}

if (Request == null)
{
  System.Diagnostic.Trace.WriteLine("Request is null");
  return;
}

HttpCookie cook = Request.Cookies["UserInfo"];
if (cook == null)
{
  System.Diagnostic.Trace.WriteLine("Cookie is is null");
  return;
}

Response.Write(Request.Cookies["UserInfo"].Values["LOBID"].ToString() + "<br>");
Response.Write(Request.Cookies["UserInfo"].Values["UserID"].ToString() + "<br>");
Response.Write(Request.Cookies["UserInfo"].Values["UserRole"].ToString() + "<br>");

Or you can try to obtain cookie like this:
HttpCookie cook;
if (HttpContext.Current.Request != null)
{
   cook = HttpContext.Current.Request.Cookies["UserInfo"];
}
Accepted Solution
 
01.18.2005 at 02:46PM PST, ID: 13077734
so i have to create a httpcookie object to read the values too..make since but still kinda crapy. and still haveing a problem

HttpCookie cook;
cook = HttpContext.Current.Request.Cookies["UserInfo"];

That above code alone works fine but if i add code to extract values from cook it give the object not set.
so the httpcookie gets set fine but cant get the values still....

Response.Write(cook.Values["UserRole"].ToString() + "<br>");
Response.Write(cook.Values["UserID"].ToString() + "<br>");

thanks for your help.
 
01.18.2005 at 02:54PM PST, ID: 13077824

Rank: Master

cookie valued are string so you don't need:

cook.Values["UserRole"].ToString()

try this:

HttpCookie cook;
cook = HttpContext.Current.Request.Cookies["UserInfo"];

string userRole = cook.Values["UserRole"];

Response.Write(userRole + "<br>");

Where you get error ?
If  error ocurre in line with "response" then Response object is null, and with cookie is everythig ok.
 
01.18.2005 at 02:59PM PST, ID: 13077871
ok tryed that and it give me the error trying to set the string to one of the cookies values

HttpCookie cook;
cook = HttpContext.Current.Request.Cookies["UserInfo"];
string test = cook.Values["UserID"]; <-----------------------error on this line.
Response.Write(test + "<br>");

dam man, whats the deal??
 
01.18.2005 at 03:01PM PST, ID: 13077882
tryed it like this too
string test = cook.Values[1];
 
01.18.2005 at 03:04PM PST, ID: 13077911

Rank: Master

Just try:
Is another page in same domain ?
 
01.18.2005 at 03:07PM PST, ID: 13077946
no..same project, same web directory, dude they are saved right next to each other.  I;m useing asp:hyperlink control on the defautt page and the navigaturl of the link is set to : http://sdad3intdev1/VenderRisk/AddVender.aspx

The two files
http://sdad3intdev1/VenderRisk/default.aspx
http://sdad3intdev1/VenderRisk/AddVender.aspx
 
01.18.2005 at 03:08PM PST, ID: 13077956
Then on the addvender page i have a button control that just does a post back then set the httpcookie and trys to get data from it.
 
01.18.2005 at 03:24PM PST, ID: 13078106

Rank: Master

>Then on the addvender page i have a button control that just does a post back then set the
> httpcookie and trys to get data from it.

On which page and in which event you set cookie ?
Try to set cookie on the first page in OnLoad event.
This way cookie will be set in first response to user. Then you will must have them on the second page.

 
01.18.2005 at 06:10PM PST, ID: 13079047
the default page sets the cookie then i click and hyperlink to go to addvender.  On the addvender page i have a button that raises the event to check the cookie.
Thanks for all the help.  I don't konw what the the deal is.  I'm at home now and when I VPN and go the site it works fine.  I even changed the code back to
                Response.Write(Request.Cookies["UserInfo"].Values["UserRole"].ToString() + "<br>");
and it works....no idea man.  I'll go ahead and give you the points since you helped me out anyways.

Do you use VS.net to dev. in? and if so does it ever put funky charters in your html like '?' or anything.  mine does and its freakn anouing.
 
 
20080236-EE-VQP-29