Changing client side cookies in .NET

I have a few cookies in my applicaiton which are created using javascript.

Now I can read the cookies no problem. I can create the cookies in .NET and read them in javascript no problem. If the cookie is created in .NET i can modify it's value in .NET no problem. If the cookie is create in javascript I can modify it's value in javascript no problem.
What I can't do is change the value of a cookie created in javascript using .NET.
I have tried every permutation of Cookies.Add, Cookies.Set, Cookies.Remove using both the response and request objects.
I can debug the code and see the value changed in the Request object (or added to the Response object), however when it gets to the client the cookie's value hasn't changed, but rather a NEW cookie with the same name gets added.
It's almost as if the javascript cookies are read only in .NET.
If anyone has any code that set a cookie in javascript, and changed it's value in .NET i would GREATLY appreciate it. If you could post both the javascript and .NET code that would be perfect.
"A programmer will write code. A developer will put it together."
0
PuckPuck
2/9/2004 11:29:23 PM
asp.net.getting-started 91979 articles. 3 followers. Follow

4 Replies
888 Views

Similar Articles

[PageSpeed] 40

It should work. Can you post some repro code?
Bertrand
----
This posting is provided "AS IS" with no warranties, and confers no rights.
0
bleroy
2/10/2004 12:26:36 AM

Javascript code to handle cookies

var docCookie = document.cookie;
var expCookie = new Date(new Date().getTime() + 24 * 60 * 60 * 1000); //add 24 hours to today
function getCookie(name) {
docCookie = document.cookie;
var index = docCookie.lastIndexOf(name + "=");
if (index == -1) return null;

index = docCookie.indexOf("=", index) + 1; // first character
var endstr = docCookie.indexOf(";", index);
if (endstr == -1) endstr = docCookie.length; // last character
return unescape(docCookie.substring(index, endstr));
}
function setCookie(name, value) {
if (value == 0 || (value != null && value != ""))
document.cookie = name + "=" + escape(value) + "; expires=" + expCookie.toGMTString();
}

I have a cookie called "contentArea" which is set to a number (0, 1, 2, 3)
Typically the cookie is set to 0, however if a certain condition is met in .NET code I need to set it to 3. I have tried all the following and none will change the cookie. The only thing I can do is add another cookie to the end of the collection.

{
Request.Cookies.Get("contentArea").Value = "3";
}
{
Request.Cookies.Add(new HttpCookie("contentArea", "3"));
}
{
Request.Cookies.Set(new HttpCookie("contentArea", "3"));
}
{
Request.Cookies.Remove("contentArea");
Request.Cookies.Add(new HttpCookie("contentArea", "3"));
}

I have also tried all the above blocks of code (not at the same time) with the Response object also. One thing I did notice, is that the expiration time is not present (or set) in the .NET objects when debugging, however I can set it explicitly in .NET and it will appear, it just won't appear if I set it in javascript.
"A programmer will write code. A developer will put it together."
0
PuckPuck
2/10/2004 12:39:21 AM
Does anyone have any example code of creating and accessing a cookie in javascript then changing this same cookie's value in .NET?
"A programmer will write code. A developer will put it together."
0
PuckPuck
2/10/2004 3:05:35 PM
I have the same problem, and the same result, two cookies with the same name.

Any solution? A bug?
0
WinMan
3/18/2004 8:09:00 AM
Reply:

Similar Artilces:

Getting Value from Client-side InputBox to .net variable
hi, im doing a login page for our timekeeping. Since there's no msgbox available on asp.net, im doing it dynamically via javascript. How do i Get the value frm a dynamically written javascript (such as inputbox) to a .net variable? here's the logic of my program, user logs in hits the button and sub-routine Login will be fired, if user is late -- call Check_Late Sub, this is whre the client-side script was built -- then after that i wanted to be able to get the value from an inputbox. '// if button login clicked Sub Login(Sender As Object, E As EventArgs) .......

Net:Net:Net::LDAP::FAQ
------_=_NextPart_001_01C6429F.D89AA417 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hello, Net::LDAP Net::LDAPS Is there a possible to LDAP bind with an encrypted (SHA, SSHA, CRYPT, ....) password? I don't like to write the secret password to the perl file. Best regards Barbara Wilbert ------_=_NextPart_001_01C6429F.D89AA417-- Wilbert Barbara (CI/OSI) * wrote: > Hello, > > Net::LDAP > Net::LDAPS > > Is there a possible to LDAP bind with an encrypted (SHA, SSHA, CRYPT, > ......

how to get value from client side script Prompt window to a session var in .net
hi guyz, i hav a problem with getting a value from a client-side inputbox to a session var in .net. is this possible? however, when i click submit button this is the code that's triggered. dim sb as New System.Text.StringBuilder sb.append("<script language=" & """" & "vbscript" & """" & ">") sb.append(vbcrlf) sb.append(vbcrlf) sb.append("do while xLate =" & """" & """") sb.append(vbcrlf) '//prompt window, val...

Side by Side Execution of .net v1.1 and .net v2.0
Hi i am new bie to asp.net 2.0.Till date i have been developing projects using VS.Net 1.1 and now i hv decided to upgrade to new version 2.0.Now i want to run and develop my projects using any of the versions as desired.My question is that can i install vs 2.0 without updating the previous version and will i be able to develop and run my applications in any of the versions as desired.i have been known that we can run these versions side by side(i.e. one application can use 1.1 and other 2.0),but can we do side by side development as well(i.e. one application can use 1.1...

Side by Side Execution of .net v1.1 and .net v2.0 (continued)
Hi, Dave wrote a previous post that said: "If you are referring to web applications - each Virtual server must specify the framework to run under.  Both can run side-by-side.. but not under the same virtual server (application pool)" That looks fine, but I wonder: Is it just as easy as going to Administrative Tools --> IIS --> Select the virtual directory --> go to the property's ASP.NET tab and then selecting the ASP.NET version? Is there some important information that I need to know before going into this? Are there going to be ANY issues I should be aware of? T...

Starting an Ajax.net Application in .net
i am new to ajax.net could any one give me simple ajax,net example so that i start building on my ajax skills please.........  I started with the todolist video on the main asp.net/ajax page, and its all you need to know to get started. http://download.microsoft.com/download/0/f/6/0f651a0f-6f2b-4497-b061-e1b2825e22e0/MSAJAX-ToDoList.wmv Don't forget to click "Mark as Answer" on the post that helped you.This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped. http://asp.net/ajax/    ...

cookies in .net 2003 and .net 2005
hi all.... i faced a problem now......my login page is created using .net 2003, and once i logged in ......i created a cookies using .net 2003, but how can i pass this cookies to .net 2005.......because some pages i created using .net 2005.... thanks goh6613:how can i pass this cookies to .net 2005 There is now difference between these two versions in accessign cookies, both use Request.Cookies for accessing cookies and user Responce.Cookies for adding new cookies. So you can create a cookie in a page written in 2003 and access it similarly in a page written in 2005.Reza Nassabehwww.p...

Developed C#.net WebService 1.1 for Client C#.net 1.1. Getting error "Server was unable to process the Request" Pls Help
Hi., I developed Microsoft C#.net Web Services2003 for the Client Application C#.net 2003. When it runs in 5 machines it gives good performance and has no errors. But if i run the same application in about 80 client machines. Getting error "Server was unable to process the request". I use Sql Server 2005 as my database. I get error even when i login at a time for about 25 users. Tried modifying machine.config too. But went unsuccessful. Live Server is 2003 using IIS 6.0 I use very expensive data handling.  Its very urgent pls help. Have to post in Live Server. Thank u., ...

Validation Controls in .NET ( Client side or server side?)
 i have a very basic question. We have all these validation controls in asp.net ( required field, range validator and others)..my question is the required field validator is a server side control. So does that mean that it does a post back?..is it client side or server side control  The only controls that post back are buttons and other inputs where you set AutoPostback="True", such as a dropdownlist or a textbox.  Another way of posting back is using an UpdatePanel and placing a trigger in it for a specified control and/or event. All controls are considered clien...

Jscript, moving from client-side to server-side (.NET)
Hey all I’m working translating a web-app written in client-side Jscript to run on the server-side as JScript.NET. Without needing to get too specific, I am using Jscript because the original page aggregated raw data to produce statistical results (this was done dynamically based on user 'sort-by' options). The final output is an html report that can be emailed. Because this is currently being done on the client side, as the raw data grows the load-time grows as well (to the point that has almost become unusable). I’m posting here to see if anyone has any experi...

.NET for client side?
Is this the idea of "Atlas" but using JavaScript rather than another technology? Atlas's goal is to abstract various browser implementations of DOM API and to ease out the developer's job to write rich client applications. Atlas hence makes use of the existing all-browser supported JavaScript to achieve this. Thanks for your reply.Let me convey my idea differently: I would like to author client side code using a class system. I recognise that Atlas is a technology for producing JS code, much in the same way that ASP.NET produces HTML for the browser.Will Atlas be m...

how to get start with .NET
the net help people installed  to my desktop 1-microsoft visual studio .NET enterprise developer 2003 2-microsoft .NET framework 1.1 what else do i need ...???  and how can i try with some simple code in VS.Net and run it to see wat happen...????? please help If you want to develope web applications, then you'll also need IIS on your PC.  That'll require XP-Professional or Windows 2000/2003, but XP-Home edition won't allow IIS installation. As for how to get started, you can search the web for some tutorials or buy a good book on VS.  The topic is way too vast to...

Getting Start With .net
hi i'm intersted to learn asp.net (vb or delphi) . i programming with delphi6 but i'd like to tp know something about programming in internet specially with .net . i hear about microsoft.net with delphi 7 that i can programming with delphi in .net .... is it right ? what 's our opinian about it ? and better to learn Vb.Net or continu with delphi(or delphi.net) thanks. Ali Darabian I think there is some support for Delphi in .Net. However, you will find much more support from the user community if you choose a more popular language such as VB.Net or C#. Since your al...

When to use client side varidation and server side varidation in .net?
In .net or classic web application we can varidate user data either on client isde or server side. How to select which side varidate to be used? Thanks! Generally, I use both client and server validation. I make sure the input is in the correct format and reasonably valid on the client, then I verify the data on the server. The extent of validation also depends on the type of data that I need to validate.Here are a few references:Validating ASP.NET Server ControlsIntroduction to Validating User Input in Web FormsClient-Side Validation for ASP.NET Server ControlsSecurity Checklist...

Web resources about - Changing client side cookies in .NET - asp.net.getting-started

Changing room - Wikipedia, the free encyclopedia
A changing room , locker room , dressing room (usually in a sports, theater or staff context) or changeroom (regional use) is a room or area ...

Beyond Timeline: The Changing Face Of Facebook Ads
Despite the hype, timeline may not be the most exciting, or important change coming on March 30. Expanded advertising opportunities may unlock ...

Robert Scoble - Micromedia, how it's changing what we blog - Facebook
Jeremiah Owyang wrote an interesting piece about micromedia and how it's changing what we do on blogs and how we distribute media (er, ideas, ...

8 Ways the Changing Facebook Home Page Will Affect Application Virality
For developers who live and die by the changes Facebook makes to the way information flows through the service, every little Facebook tweak has ...

Changing Lanes (@chginglanes) on Twitter
Sign in Sign up To bring you Twitter, we and our partners use cookies on our and other websites. Cookies help personalize Twitter content, tailor ...

Changing the way business decisions are made
We believe that social data has unlimited value, and near limitless application. Today, we’re taking an important step toward unleashing this ...

The Right and Wrong Reasons for Changing Jobs
... your profile is a clue to the folks at LinkedIn that you’re thinking of switching jobs, so don’t be The Right and Wrong Reasons for Changing ...

We're Changing Our Name (Back) to Stack Overflow
We are Stack Overflow. You may know us from such popular websites as Stack Overflow Q&A, Stack Overflow Careers, The Stack Exchange Q&A Network, ...

The Tao of Twitter: Changing your life and business 140 characters at a time - Amazon
It's time to take the mystery out of Twitter. Twitter may be the most powerful business and personal networking platform ever created but it ...

App Store - Voices 2 ~ fun voice changing!
Read reviews, get customer ratings, see screenshots, and learn more about Voices 2 ~ fun voice changing! on the App Store. Download Voices 2 ...

Resources last updated: 1/9/2016 12:18:46 AM