Search EggHeadCafe's Job Board
EggHeadCafe Silverlight WPF ASP.NET VB.NET C# Excel SQL Server SharePoint
search
MicrosoftArticlesForumsFAQs
C# .NET
VB.NET
Visual Studio .NET
ADO.NET
Xml / Xslt
VB 6.0
.NET CF
GDI+
LINQ
Deployment
Security
FoxPro
Silverlight / WPF
Entity Framework
RIA Services

WebArticlesForumsFAQs
JavaScript
ASP
ASP.NET
WCF

DatabasesArticlesForumsFAQs
SQL Server
Access
Oracle
MySQL
Other Databases

OfficeArticlesForumsFAQs
Excel
Word
Powerpoint
Outlook
Publisher
Money

Non-MicrosoftArticlesForumsFAQs
NHibernate
Perl
PHP
Ruby
Java
Linux / Unix
Apple
Open Source

Operating SysArticlesForumsFAQs
Windows 7
Windows Server
Windows Vista
Windows XP
Windows Update
MAC
Linux / UNIX

Server PlatformsArticlesForumsFAQs
BizTalk
Site Server
Exhange Server
IIS

Graphic DesignArticlesForumsFAQs
Macromedia Flash
Adobe PhotoShop
Expression Blend
Expression Design
Expression Web

OtherArticlesForumsFAQs
Lounge
Subversion / CVS
Ask Dr. Dotnetsky
Active Directory
Networking
Uninstall Virus
Job Openings
Product Reviews
Search Engines
Resumes

 

  View Other Ask Dr. Dotnetsky Posts   Ask New Question  Ask New Question With Power Editor

Cookies problem in silverlight 2.0
divya rocks posted at Tuesday, April 08, 2008 6:42 AM

hi.

how to remove cookies in silverlight application...!!

i have on login page(aspx) in  taht button click  i create cookies .

before that i  write code in pageload for deleting  cookies  like

HttpCookie hc = new HttpCookie("");

button click

HttpCookie hc = new HttpCookie(userdetails[0], userdetails[1]);

hc.Expires = DateTime.MinValue;

Response.Cookies.Add(hc);

 

i call this cookie in xaml page(silverlight 2.0)

 

using System.Windows.Browser;

  string  str = string.Empty;

str = HtmlPage.Document.Cookies;

Empid = str.Split('=')[1];

 

}

private static string _empid = string.Empty;

public static string Empid

{

get { return UserDetails._empid; }

set { UserDetails._empid = value; }

}

. here my problem  is  i  have logout button in xaml page.. when  i click it i redirected to login page..., again  i login with another username and password..,  in  string str, it showing old values and new values... how to delete cookies when i log out..

thank u

 

Reply    Reply Using Power Editor
  Rank Winnings Points
November 0 $0.00 0
October 0 $0.00 0
Cookie
Aravind Kumar provided a rated reply to divya rocks on Tuesday, April 08, 2008 7:13 AM

This statement HttpCookie hc = new HttpCookie("") will never delete cookies, rather it'll just create a persistant cookie (and deletes a cookie if the client system has reached max cookie limits). Its always advisable to create a cookie with a name. So after creating it, give a expiry minvalue as you do.

Finally, when you logout of the application, this statement will surely remove your cookie from the client - Response.Cookies.Remove("CookieName");

Hope this helps.

Reply    Reply Using Power Editor
  Rank Winnings Points
November 53 $0.00 2
October 0 $0.00 0

Delete Cookie
Sanjay Verma replied to divya rocks on Tuesday, April 08, 2008 11:42 PM

Write the following statement on your logout button click event ::

Response.Cookies.Remove("hc");
Response.Redirec("Your Login Page");

Hope this helps.....

you can refer this link for your knowledge...

http://forums.asp.net/t/1227365.aspx

Reply    Reply Using Power Editor
Asp.Net Developer
  Rank Winnings Points
November 0 $0.00 0
October 0 $0.00 0

retrieve and delete cookies within a Silverlight application.
Rakesh Vikram provided a rated reply to divya rocks on Tuesday, May 13, 2008 3:11 AM

Try to implement this logic within your application. The below code retrives an existing  cookie and deletes the specified cookie.

---------------------------------------------------------------------------

/// <summary>
/// sets a persistent cookie with huge expiration date
/// </summary>
/// <param name="key">the cookie key</param>
/// <param name="value">the cookie value</param>
private static void SetCookie(string key, string value)
{
    string oldCookie = HtmlPage.Document.GetProperty("cookie") as String;
    DateTime expiration = DateTime.UtcNow + TimeSpan.FromDays(2000);
    string cookie = String.Format("{0}={1};expires={2}", key, value, expiration.ToString("R"));
    HtmlPage.Document.SetProperty("cookie", cookie);
}

/// <summary>
/// Retrieves an existing cookie
/// </summary>
/// <param name="key">cookie key</param>
/// <returns>null if the cookie does not exist, otherwise the cookie value</returns>
private static string GetCookie(string key)
{
    string[] cookies = HtmlPage.Document.Cookies.Split(';');
    key += '=';
    foreach (string cookie in cookies)
    {
        string cookieStr = cookie.Trim();
        if (cookieStr.StartsWith(key, StringComparison.OrdinalIgnoreCase))
        {
            string[] vals = cookieStr.Split('=');

            if (vals.Length >= 2)
            {
                return vals[1];
            }

            return string.Empty;
        }
    }

    return null;
}

/// <summary>
/// Deletes a specified cookie by setting its value to empty and expiration to -1 days
/// </summary>
/// <param name="key">the cookie key to delete</param>
private static void DeleteCookie(string key)
{
    string oldCookie = HtmlPage.Document.GetProperty("cookie") as String;
    DateTime expiration = DateTime.UtcNow - TimeSpan.FromDays(1);
    string cookie = String.Format("{0}=;expires={1}", key, expiration.ToString("R"));
    HtmlPage.Document.SetProperty("cookie", cookie);
}

---------------------------------------------------------------------------

For more information, on cookies properties:

http://msdn2.microsoft.com/en-us/library/ms533693(VS.85).aspx

Hope this helps in provinding a solution.

Rakesh Vikram

 

 

 

Reply    Reply Using Power Editor
  Rank Winnings Points
November 0 $0.00 0
October 0 $0.00 0

Silverlight
wang mingjun replied to divya rocks on Tuesday, September 22, 2009 3:17 AM

end of post
Reply    Reply Using Power Editor
  Rank Winnings Points
November 0 $0.00 0
October 0 $0.00 0