Tracking Forums, Newsgroups, Maling Lists
Home Submit Tracker Forums
  Advanced Search


State Management :: How To Serialize An Object Into Cookie

I had an xml-serialization which worked fine, but as I have just knew it doesn't work in Opera browser. I think, it's security rules don't allow to write to cookies xml-content.What can I do? Can I use binary serialization or something else?

View 2 Replies (Posted: Apr 01, 2010 06:18 PM)

Sponsored Links:

Related Forum Messages For ASP.NET category:
State Management :: How To Store Object In Cookie With C#
I'm using session to store C# object but my session is expiring regularly.

I've given 540 minutes for session timeout. ( <sessionState mode="InProc" timeout="540"/>)

Now I want to use cookie instead of session to remove this timeout problem.

code below:


Posted: Apr 10, 2010 02:55 PM

View 17 Replies!   View Related
State Management :: Unable To Serialize The Session State In 'StateServer' And 'SQLServer' Mode
I am new to .net 4.0 and am using EF Model and SessionState Mode=SqlServer and I am getting this error below:

Unable to serialize the session state. In 'StateServer' and 'SQLServer' mode, ASP.NET will serialize the session state objects, and as a result non-serializable objects or MarshalByRef objects are not permitted. The same restriction applies if similar serialization is done by the custom session state store in 'Custom' mode.

I checked the stack trace and its complaining about

[assembly: global::System.Data.Objects.DataClasses.EdmSchemaAttribute()]
[assembly: global::System.Data.Objects.DataClasses.EdmRelationshipAttribute("PoplarGroveModel", "tblMenuRole", "tblMenu", global::System.Data.Metadata.Edm.RelationshipMultiplicity.Many, typeof(PoplarGroveDataModel.Menu), "tblRole",


I marked it as serializable but then it complains about System.Data.Objects.ObjectContext is not marked as serializable and hence throws the same error.

Posted: Dec 12, 2010 11:48 AM

View 1 Replies!   View Related
State Management :: Remove Item (Cookie) From Basket (Cookie Collection)?
I am busy building a shopping cart with cookies. Ihave datalist which I populate from the cookies with a delete button next to each cookie


Now the problem is that when I hit the delete / removebutton to expire the cookie,what happenswhen repopulating the datalist is thatit shows the original cookie with all it's values as well as a new entry where all the values are blank.

Posted: Sep 08, 2010 10:02 AM

View 3 Replies!   View Related
State Management :: Updating Cookie / Change The Value In A Cookie?
I want to change the value in a cookie:
HttpCookie hc = new HttpCookie("HiddenColumns");
hc.Value = customView.HiddenFields;
hc.Expires = DateTime.Now.AddDays(365);

Or this way:

Response.Cookies["HiddenColumns"].Value = customView.HiddenFields;;
Response.Cookies["HiddenColumns"].Expires = DateTime.Now.AddDays(365);

But when I retrieve the cookie value, it is still old, unless I do postback. I don't want to use Redirect.

Posted: May 10, 2010 01:00 PM

View 2 Replies!   View Related
State Management :: Serialize TreeNode With Sql?
Currently I am working on SessionState with SQL. I have problem. I would like to serialize TreeNode. This TreeNode pbject will be assigned to Session and this is declare as below.

private _treeNode as TreeNode <-- member variable

how do I make this _treeNode seriablizable?

Posted: Jan 21, 2011 04:16 AM

View 1 Replies!   View Related
State Management :: How To Serialize Objects
Is there any way or process to serialize the the objects?? i am trying to store the instance of few control in viewstate but it shows error msg that it is not a serialized object. should i perform some steps to serialize the objects ???

Posted: Jul 02, 2010 12:45 PM

View 9 Replies!   View Related
State Management :: Serialize/Deserialize A Custom Class In And Out Of A Session
I'm trying to save a custom class in a session, but it just never gets saved, along with other sessions. Note that my SessionMode = STATESERVER, and i cannot change it to INPROC as per our business requirement. This is my class

public class User : ISerializable
private int _userId;
public int UserId
get { return _userId; }
set { _userId = value; }
//custom class
private TDB.tdbUser _tdbUserDetails;
public TDB.tdbUser tdbUserDetails
get { return _tdbUserDetails; }
set { _tdbUserDetails = value; }
//collection of custom class Sites
private List<Sites> _assignedSites;
public List<Sites> AssignedSites
get { return _assignedSites; }
set { _assignedSites = value; }
public User()
//Constructor code
protected User(SerializationInfo info, StreamingContext context)
this._userId = (int)info.GetValue("_userId", typeof(int));
this._assignedSites = (List<Sites>)info.GetValue("_assignedSites", typeof(List<Sites>));
this._tdbUserDetails = (TDB.tdbUser)info.GetValue("_tdbUserDetails", typeof(TDB.tdbUser));
[SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.SerializationFormatter)]
void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
info.AddValue("_userId", this._userId);
info.AddValue("_assignedSites", this._assignedSites);
info.AddValue("_tdbUserDetails", this._tdbUserDetails);

The calling code is just this: (User)HttpContext.Current.Session["TDBUSER"];

Posted: Mar 18, 2011 06:13 PM

View 2 Replies!   View Related
State Management :: Asp Create New Session State Cookie Each Time On Debugging?
I'm using the following line ofcode todisplay the number ofuserscurrently logged on:

lblNoOfUsers.Text = Membership.GetNumberOfUsersOnline().ToString()

I'm stilldebugging my application so it's on the local server.As I debug and stop then debug again, eventuallylblNoOfUsers.text turns to "0" instead of "1", even as I'm navigating my application. It only turns to"1" again if I log out and sign back in. It's almost as though Membership.GetNumberOfUsersOnline my login are referencing two different session states.How is this possible?Does create a new session state cookie each time I start debugging?

Posted: Jan 21, 2011 07:10 PM

View 2 Replies!   View Related
State Management :: Can't Get Value Cookie
i have trouble about cookie path: I use VS 2005, code as:

HttpCookie aCookie = new HttpCookie("lastVisit");
aCookie.Value = DateTime.Now.ToString();
aCookie.Expires = DateTime.Now.AddSeconds(30);
aCookie.Path = "/TestCookie";

Seem that , i can't get value cookie,although my variable on page which inside TestCookie folder I try get cookie other pages which outside TestCookie folder ! Result is like before attempts.

Posted: Jul 06, 2010 01:56 AM

View 4 Replies!   View Related
State Management :: Cookie Value Disappeared?
We are using and 3.5 framework. I have a process thatsets the value of a cookie named "mystaffid" in the Default.aspx code behind page. This holds the unique ID of the internal user (intranet).Now when I leave one of the web pages to go to another page in the same website I am getting the error "Input string was not in a correct format." on the 3rdline below. how the cookie disappears? Also, this is happening in the Page_Load of the master page and I am doing the exact same thing in other pages with the same master page and not getting the error. The cookie is set to expire in 1 day when it is set in Default.aspx.

Dim intStaffID As Int32 = 0

If Not Request.Cookies("mystaffid") Is Nothing Then
intStaffID = Convert.ToInt32(Request.Cookies("mystaffid").Value)
End If

Posted: Feb 13, 2011 06:23 PM

View 2 Replies!   View Related
State Management :: Get New Session Cookie In IE7?
We have a local homepage, which connect to our production security environment. When I need to test my site in test environment, I need to get fresh cookie (not the one that was sent to me via production security service, when I opened IE with local homepage).

I am getting fresh cookie fine in Mozilla; but in IE I always have production cookie, and this disables my testing. What I should fix here?

Posted: Oct 22, 2010 10:34 PM

View 4 Replies!   View Related
State Management :: Way To Make Cookie That Contains A List
I want to make a cookie that contains a list and then i want to be able to get the information from the list by entering the list items specific key value. I quickly made a test application to see if it works or not and the code that im posting below is Not working


Posted: Jun 03, 2010 07:31 AM

View 7 Replies!   View Related
State Management :: Cannot Create A Simple Cookie
Very new to ASP.NET and C# (somewhat knowledgable in PHP) I have an ASP.NET web application and need to manage access to pages based on a 'status' stored in a cookie. I would like to use the following code to create the cookie in a login method.

HttpCookie cookie = new HttpCookie("UserCookie");
cookie.Value = "status"; <-- this will be replaced with a variable once its working
cookie.Expires = DateTime.Now.AddHours(1);

My problem is that the only place I can put this code where it works is in the global.asax Session_Start method. It simply doesn't work anywhere else. I am checking the cookie creation in firefox options and see the ASP.NET_SessionId created but nothing else (This is all running on localhost).

Is the session status somehow interfering with the cookie creation? Do I need to configure something in Web.config? It would appear that the only time I can create a cookie is on Session_Start. Does anyone have any tips, perhaps I am missing something simple?

Posted: Feb 28, 2011 08:06 PM

View 6 Replies!   View Related
State Management :: Cookie Does Not Work On Server?
I am developing a 3.5 web site. Cookie is used to store username when site user logins in the site.This works well on my local computer when I'm debugging it with Visual Studio.But when I publish the site and upload it to the server, cookie could not store username.

My code is as below:


HttpCookie loginState = new HttpCookie("loginState",email);


Posted: May 04, 2010 05:35 AM

View 8 Replies!   View Related
State Management :: Cookie / It's Cause The Sql Server Update Twice :|
I have a website of online games and I try to count and show the number of the uniqe visitor per game page, by using Cookies only. (if someone visit after 24hr it will be uniqe visitor too)

the problems is:sometimes (I don't know why), not always, it's update the counter colomn of the game, +2 instead +1, and I don't know why, there isn't any "for loop" etc.. maybe is't because the url rewrite? but it work fine if people enter again the colomn will not update again, the problem is that is update +2 instead +1 (see the code at the bottom)this is my algorithm (something is wrong in this algorithm so don't use it):

1. put the query string in variable (the name of the game) - i'm using url rewite.

2. use this variable for select the game Name (and another information) from the database (and for the cookie I will use the game name from the database and not from the query string to avoid from capital letter problems, because cappital letter for the first word isn't good because words like of, to etc..).

3. for each pageload (there isn't postback in the game page) check if the cookie of the uniqe game exists

4. if not exists, create a cookie for the unique game (the name of the cookie and the his value will be same, because I don't care about it, it's only for check if the cookie exist, and I can't use one cookie for all the games because each time visitor enter the cookie will create for 1 day).

4. after this creation of the cookie try to find if the cookie exist (for cheaking if the user didn't disable the option for cookies)

5. if yes update the database column of the spesific game

the code:

In the end of the page_load - (the GameName is the virable of the name of the game from the database and not from the qury string).


and the update function


Posted: Dec 22, 2010 06:43 PM

View 4 Replies!   View Related
State Management :: How To See The Sessionid Cookie On IE Browser
Iwant to see the asp.net_sessionid cookie on my IE browser.Where can Ifind it ?

Posted: Apr 08, 2010 07:45 AM

View 8 Replies!   View Related
State Management :: How To Look At The Actual Cookie That Is Passed To .net
Our app uses session to keep track of users. We stuff their user id into session on logon. If the browser cache is cleared any refresh to the page is done then the user will see the log out sign - as the app cant get theuser id from session as the aspnet_session cookie wont be present in the request.Firefox works correctly but when I clear the cache on i.e. the session is maintained. The session ID's are the same for multiple I can debug the app to see what cookies its getting. How do I look at the actual cookie that is passed to .net?

Posted: Nov 09, 2010 10:09 AM

View 2 Replies!   View Related
State Management :: How To Save Value In Cookie And Retrieve It
How can I save a variable x with the value yin a cookie k and how can I recetrive the value y ?For how long will the cookie be available?

Posted: Jul 19, 2009 10:15 AM

View 4 Replies!   View Related
State Management :: Read Cookie Value In Other Page?
Can we read cookies value in another pageaccept where we created it.

If yes can you show me how?

HttpCookie cookieCode =

I have already created cookie,now I need to read it in other page

Posted: Aug 05, 2010 05:38 PM

View 1 Replies!   View Related
State Management :: Change Session Cookie Name?
I would like to change ASP.NET session cookie name "ASP.NET_Sessionid" to some other name. I specified <sessionState cookieName="MyCookieName" />. When I use fiddler to view response header, I can see "MyCookieName" with random generated number under cookie section, however, ASP.NET_SessionId also exist there.

Posted: Dec 15, 2010 02:34 AM

View 2 Replies!   View Related
State Management :: Cookie In Session_Start Is Always Null?
I want in Session_Start method check if cookie with specific key exists and if not create cookie with this key.

if (HttpContext.Current.Request.Cookies[key] == null)

But in Session_Start it is always NULL. If check it in another place I get cookie's value.

Why is it always NULL in Session_Start?

Posted: Oct 27, 2010 01:13 PM

View 9 Replies!   View Related
State Management :: Change Cookie Value Of Website?
I use cookie to change the language of my website.

When I click aLinkButton to change the language for first time it works but the other button doesn't work to change the language . I should delete cookie to change the language.

<asp:LinkButton ID="LinkButtonEn" runat="server" CommandArgument="en-US" OnCommand="LnkLang_Command"Text="English"></asp:LinkButton>
protected void LnkLang_Command(object sender, CommandEventArgs e)
Response.Cookies["mylang"].Value = "";
Response.Cookies["mylang"].Value = e.CommandArgument.ToString();

Posted: Aug 28, 2010 06:06 AM

View 3 Replies!   View Related
State Management :: How To Get The Cookie Expiration Date To Write Out
I tried <%= request.cookies("cookiename").expires%> but thats a no go. Tried adding .tostring, no go. what am I to do? Has to be something simple I am missing here.

Posted: Nov 01, 2010 07:26 PM

View 6 Replies!   View Related
State Management :: How To Encrypt And Decrypt Cookie Name And Values
How to encrypt and decryptcookie name and values?

Posted: Mar 31, 2010 12:51 PM

View 3 Replies!   View Related
State Management :: Random Value Cookie For Each Page Request?
How do I create random value cookie for each Page Request in ASP.Net CS file.

Random value cookie should have server path.

Posted: Nov 19, 2010 05:01 AM

View 4 Replies!   View Related
State Management :: Accessing Cookie From Windows Service?
I have a URL (1) if i hit that URL using HttpWebRequest i get another URL (2) and if i hit the URL (2) i get XML and i process that XML and insert into my database.

I can hit the URL (1) and get the URL(2) but if i hit the URL (2) i am not getting XML. i think i need to pass some cookie info for authentication but i dont know how to do that in windows service[URL]

Posted: May 09, 2010 07:15 AM

View 2 Replies!   View Related
State Management :: Sharing Cookie Between Two Webapps On Localhost?
If I want to share cookies among applications, applications need to be inthe same domain. In production it is no problem. But I have problem with development. If I runthose applications in Visual Studio, it runs application in"localhost" and it is not same domain. I don`t seecookies among applications.

Posted: May 17, 2010 01:13 PM

View 1 Replies!   View Related
State Management :: Session Not Retained / Cookie Not Accessible?
I have a website for a simple game. When people sign in their Player ID is stored in a Session variable. I have integrated SMS payments so that my players can buy credits to use to play. This is where the problems start:

To buy credits, players are presented with an .aspx page that holds an IFRAME of the SMS payment proviers form. A code is entered, and the IFRAME POSTS to a URL on the providers server. It is then redirected back to an URL on my server(, where I handle the results (i.e adds credits to th players account if the payment was successfull).

However, the session dies on return.

I tried with cookies, and saves the player ID in a cookie, but when upon return to I cannot read the cookie? I'm checking for if (cookie == null) and it evaluates to TRUE, so the player is redirected to an error page.

How come the cookie cant be read? Is it because the POST is coming from an outside URL? And, what about when I do it with a session variable? Same thing there?

Posted: May 21, 2010 11:22 PM

View 2 Replies!   View Related
State Management :: Session Id Itself Travelling In The Cookie Values?
If I have two "webroles" (azure), that are NOT using a shared custom state provider, is the "Session.SessionID" be the same in both?It would make sense ,considering that both get the same cookie (because are in the same domain) and have the same machineKey, but I'm not sure

Posted: Feb 21, 2011 10:05 AM

View 3 Replies!   View Related
State Management :: Using Cookie In Uploadify Only Works In IE Not FF And Chrome?
I have a situation that is need of attention.The following code is inside of a .ashx file, and is used in the Uploadify JQuery Script.(Here is a sample of the working IE/non-working FF,Chrome code) file is never seen, it is only used behind.In IE you can upload images when you are logged in.In FF and Chrome you can only upload images when you are logged in with IE.(That is not right is it?)So, what is wrong, I know that the cookie script is functioning properly within the .ashx file, as I have test with another JQuery page and it works across all browsers, but when I use the cookie code in this, it acts wierd in FF and Chrome.Please someone enlighten me on this issue.What is going on with the cookie with Uploadify.


Posted: May 12, 2010 11:59 PM

View 2 Replies!   View Related
State Management :: Persisting The Cookie Across Development And Production Server?
I am using this code to passvariables from ASP.NETapplication toHTML Application:


The above code is run from page_laod event, and I am making some development changes on the Development Machine (say

After the ASPX pageis loaded,andI debug the javascript in the HTML (F12 under IE8), and can see the Cookie is found in the browser.

But, when I open the target HTML/Javascript web page (which will read the cookie prmStaffID), butthe HTML Pageis on the production machine (separate server say

http://prod01/Attendance.html), the Cookie is not found !!!

It seems to me that Cookies will persist only on one IIS Server, and will not be global.

Question:How I can persist the Cookie on the Client Machine regardless of the the Server Machine ?

For testing purposes, I want to send the cookie to the client from teh Development Server, but the target application is under HTML/Javascript, and I want to be able to read the same Cookie using Javascript.

Posted: Jan 02, 2011 07:47 AM

View 5 Replies!   View Related
State Management :: Authentication Cookie Expiration Not Sliding Properly?
we have a web based application that let users register, activate their account and then login to use the app...

it is very important that accounts must not be used simultaneously, so if user a is logged in using mynameisA/mypassword, no one else can login at the same time using the same credentials, until he logout.

this was achieved by using a cache mechanism that inserts an entry specific to that user and will keep on refreshing at each request, until the user logouts, where we remove that cache entry. on login, we check whether that cache entry is there in order to allow him in or throw a message saying that the user is already logged in... we use enterprise library 5.0 which we found more reliable than the cache, and for various other practical reasons.

now, this works fine, but the problem is that it seems like the authentication ticket and cookie doesnt slide properly at each request. so sometimes, users end up logged out because their authentication ticket got expired, and they cannot login again because the cache entry is still there.

here is the code in the sign-in page:

' if user credentials are valid, and other checks and validations...


here is the code that runs on every authenticated request (httpmodule):


and here is the web.config stuff:


we've done all kind of tests including metabase IIS6 monitoring. there is no apppool recycle happening...

checking the authentication cookie in firefox view cookies option shows that on each request, the expiration time of the authentication cookie is not sliding.

Posted: Mar 28, 2011 10:30 PM

View 7 Replies!   View Related
State Management :: How To Read Cookie Information When Using Mozilla FireFox
I am Trying To get information I stored in the cookie after create it , it's works fine when using IE8 in browsing website but i face problems in Mozilla

ttpCookie cookie = Request.Cookies["HMS_ACC"];if (cookie!=null) { if (PublicFunctions.CheckUser(cookie.Values[0].ToString(), cookie.Values[1].ToString())) { PublicFunctions.CreateSession(cookie.Values["UserName"].ToString(), cookie.Values["Password"].ToString()); return true; } else { return false; } }

Posted: Jul 11, 2010 10:09 PM

View 2 Replies!   View Related
State Management :: How To Set Cookie Expiry Time Towards 20mins From The Last Request
how to set the cookie expiry time towards 20mins from the last request.

Posted: Dec 25, 2010 04:37 AM

View 2 Replies!   View Related
State Management :: Adding A Cookie To A Response.redirect Vs. HttpWebRequest
I need to be able to redirect the browser to a new 3rd party page while at the same time supplying a cookie required for some form of authentication on the 3rd party site.

I have managed to get this to work in the following manner:


This works wonderfully, if I look at the searchResponse I see the target page.

The problem is, I need the client to handle this request, I just want to redirect to 'where I want to go' and supply the necessary cookie, but the following isn't working for me, the cookie never gets sent:


For some reason I don't understand, the cookie is discarded and never gets sent...any thoughts? Is there some other way I can acheive this?

Posted: Jan 22, 2009 05:56 PM

View 4 Replies!   View Related
State Management :: Redirect Causing A Loss Of Session Cookie?
We have a web app running .net 1.1 that users must login to access (uses FormsAuthentication). At one point, the user submits a form that is handled by aseparateweb app on the same website but in a different directory (running .net 2.0 and not requiring authentication). When the user submits the form and is redirected to this other page they have some options including returning to the previous web app.

We need our users to stay logged in to the first web app so they do not have to log in again when returning. This works fine on 3 out of four computers, but the fourth computer is asked to log in when they hit the return button (by reviewing the active cookies we see that when it returns to the original web app, the FormsAuthentication cookie is missing)

why this cookie would disappear on one machine but not the others? I am going through IE settings now but the machine has the problem in IE and Chrome (not sure if this would be a shared setting) If it is an IE setting is there a way to make this work without requiring the user to change their settings and without switching to cookieless sessions?

Here is the authentication part of web.config


And if it makes a difference, the redirect and form action property use a the full path, would using a relative path likely change anything?

Posted: May 17, 2010 10:08 PM

View 2 Replies!   View Related
State Management :: How To Send And Receive Unique Cookie To User
I need to send a cookie to the my web site's visitors and receive them back for information. For example when machine1 visits my site if not set I set a cookie with "user1", for machine2 I set "user2" etc.

Actually I need to retrieve the cookie back from my log file, so I thought if I do this it will be saved to my log file.

Posted: Oct 10, 2010 11:50 PM

View 5 Replies!   View Related
State Management :: Value Of The Cookie To Increase Only If The Page Is Not Being Accessed Due To A Postback?
I need to write code that displays the number of times a user has accessed it. I need the value of the cookie to increase only if the page is not being accessed due to a postback.So basically it will display the following on screen: 'you have visited this site 10 times' What language I use is up to me but I prefer working with VB in

Posted: Nov 29, 2010 10:04 PM

View 6 Replies!   View Related
State Management :: Cookie Working Differently In IE Explorer 8 And Chrome 5.0.375.70?
In my webconfig file, I am using Forms authentication and I have:


and my default.aspx page is protected as it should. After logging with the proper credentials I am directed to the protected default.aspx page, however when viewing other pages of my website in chrome, and then going back to the default.aspx page something strange happens. From certain pages in my website the default.aspx redirectes me to the login.aspx page, but not from all pages, only certain ones. This behaviour dosenot accour at all in IE Explorer8 where once I am properly validated in my login.aspx page, I can view the default.aspx page from all other pages in my website until I logout from default.aspx page.

Posted: Jun 13, 2010 03:01 PM

View 2 Replies!   View Related
Copyright 2005-08, All rights reserved