BAPSDude
BAPSDude

Reputation: 341

Save Cookie in Silverlight Application

I have a silverlight Web Application and want to save user credentials if it checks "Keep me signed in" checkbox.

if (KeepMeSignedIn)
                    {
                        SetCookie("CECrd", userName, password);
                    }

The Set cookie function is as folows..

private static void SetCookie(string key, string uname, string password)


        {
            string cookieName = "CECrd";
            string oldCookie = HtmlPage.Document.GetProperty(cookieName) as String;
            DateTime expiration = DateTime.UtcNow + TimeSpan.FromDays(2000);
            string cookie = String.Format("{0}={1}={2};expires={3}",key,uname, password, expiration.ToString("R"));
            HtmlPage.Document.SetProperty(cookieName, cookie);
        }

But i am unable to save the cookie in the browser. Please help me out.

Upvotes: 1

Views: 713

Answers (1)

iCollect.it Ltd
iCollect.it Ltd

Reputation: 93601

Cookies consist of name-value "pairs"

e.g.

  • Name=value
  • AnotherName=AnotherValue
  • expires=somedate

Your string.format has a property with 2 equals signs in it!

string cookie = String.Format("{0}={1}={2};expires={3}",key,uname, password, expiration.ToString("R"))

Which generates "{key}={uname}={password};expires={somedate2000daysfromnow}" which is two entries:

  • {key}={uname}={password}; // invalid
  • expires={somedate2000daysfromnow} // Valid

Upvotes: 2

Related Questions