Ask Dr. Dotnetsky - Cookies problem in silverlight 2.0

Asked By divya rocks
08-Apr-08 06: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

 

Cookie  Cookie

08-Apr-08 07: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.

Delete Cookie  Delete Cookie

08-Apr-08 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

retrieve and delete cookies within a Silverlight application.  retrieve and delete cookies within a Silverlight application.

13-May-08 03: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

 

 

 

Silverlight  Silverlight
22-Sep-09 03:17 AM
end of post
Create New Account
help
alot var Hi What are Master Pages in ASP.NET? or What is a Master Page? ASP.NET master pages allow you to create a consistent layout for the pages in your application. A single master page defines the look and feel and standard behavior that you want for all of the you want to display. When users request the content pages, they merge with the master page to produce output that combines the layout of the master page with the content from the content page. What are the 2 important parts of a master page? The following are the 2 important parts of a master page 1. The Master Page itself 2. One or more Content Pages Can Master Pages be nested? Yes, Master Pages
SilverLight What is SilverLight, its concept, why to use it and how to use it What is Silverlight? Silverlight is a new cross-browser, cross-platform implementation of the .NET Framework for building and browsers, including Microsoft Internet Explorer, Mozilla Firefox, Apple Safari, Opera. The plugin required to run Silverlight is very small in size hence gets installed very quickly. It is combination of different platform that allows you to select tools and the programming language you want to use. Silverlight integrates seamlessly with your existing Javascript and ASP.NET AJAX code to complement functionality which you have already created. Silverlight aims to compete with Adobe Flash and the presentation components of Ajax . It also competes with Sun Microsystems' JavaFX, which was launched a few days after Silverlight. Currently there are 2 versions of Silverlight: Silverlight 1.0 : Silverlight 1.0 consists of
silverlight and wpf difference if one person has gain master in silverlight than wiil this help him in learning wpf Hi Malik, WPF has a more advanced and mature XAML support than Silverlight. Silverlight used to be called (WPF / E) and is a subset of the WPF XAML design well and other items. WPF is hardware accelerated and supports things like GPU shaders which Silverlight 2 does not. Silverlight 2 does have the VisualStateManager inside Blend 2, which I think WPF needs an add on and a tweak to work. I think that is the only case where Silverlight 2 XAML was / is slightly ahead of WPF's. Here is a link on XAML us / library / cc917841(VS.95).aspx Here is a good article on MSNMAG about designing Silverlight / WPF apps together and sharing code: http: / / msdn.microsoft.com / en-us / magazine / cc895632.aspx
General discussion Helo to all Plz tell me only 10-15 important questions in Silverlight that mostly asked by Interviewer. . and if possible plz tell me interview question for ASp www.dotnetfunda.com / interview / showcatquestion.aspx?category = 84 http: / / www.aired.in / 2010 / 03 / microsoft-silverlight-interview.html http: / / www.dotnetobject.com / Thread-Silverlight-Interview-Questions-Answers HI read this Is Silverlight supported on various locales? Ans: Silverlight installs on localized versions of Macintosh computers and Windows. At this time, the installation is render international text (using double-byte characters) and support the full 64K Unicode character set. Silverlight uses simple input mechanism that treats all the languages in the same way. Ques: 2 Can I add more than one .xaml pages in silverlight application? Ans: Yes, you can have multiple .xaml files in a single project. In the App.xaml, in the method Application_Startup you can choose, which page you want to initially display. Ques: 3 What is Silverlight Tool Kit? Ans: Silverlight Tool