programming we consider all important topic for knowledge about controls,web Services, JSON, Ajax, database, and interview related Question. In this and sql server tutorial blog we give many examples of jquery as like How Play YouTube Video in Your Website by URL, How to Play YouTube Videos in by using Jquery , Jquery Change div background on mouseover in , JQuery UI Datepicker (Calendar) etc.

Tuesday, September 30, 2014

Cookies,how to make Cookies in with C#.

 What are Cookies, Make Cookies in with C#:


  • Cookies are small part of information generated by a Web server.
  • Cookies stored in the user's computer (Local Machine).
  • Cookies use for future access.
  • Cookies are embedded in the HTML information flowing back and forth.
  • Shear information between the user's computer (Local Machine) and the servers.
  • Cookies allow user-side customization of Web information.
For example, cookies are used to personalize Web search engines (information).
Many organizations and companies use ``cookies'' to track your every move on their site. Cookies, Session, and Application object are in

Advantages of Cookies:

We consider following advantages of using cookies in a web application.
  • It's very simple to use and implement.
  • Browser takes care of sending the data.
  • The browser automatically arranges them.

Disadvantages of Cookies:

Consider following disadvantages of cookies are
  • It stores data in simple text format, so it's not secure at all.
  • There is a size limit for cookies data (4096 bytes / 4KB).
  • The maximum number of cookies allowed is also limited.
  •  Most browsers provide limits the number of cookies to 20.
  • We need to configure the browser.
Now we create a web page and make cookies and save in browser.

How to create Cookies in

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Cookies_Demo.Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<head runat="server">
    <style type="text/css">
            color: #990000;
            text-decoration: underline;
    <form id="form1" runat="server">
    <div align="center">
        <h1 class="style1">
            How to Add Cookies Demo</h1>
            <table style="height: 153px; background-color: #C0C0C0">
                    <td align="right" style="font-weight: 700">
                        Enter E-Mail Id or User Name :<br />
                        &nbsp;<br />
                        Enter Password :
                        <br />
                        <br />
                        <asp:CheckBox ID="CheckBox1" runat="server" Text="Remember me" />
                    <td align="left">
                        <asp:TextBox ID="TextBox1" runat="server" placeholder="Email" Width="198px"></asp:TextBox>
                        <br />
                        <br />
                        <asp:TextBox ID="TextBox2" runat="server" placeholder="Password" TextMode="Password"
                        <br />
                        <br />
                        <asp:Button ID="Button2" runat="server" Text="Login" OnClick="Button1_Click" />

How to create Cookies in by C#:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Cookies_Demo
    public partial class Default : System.Web.UI.Page
        protected void Page_Load(object sender, EventArgs e)
            /* Checking for cookies */
            if (!IsPostBack)
                if (HttpContext.Current.Request.Cookies["UserInfodemo"] != null)
                    string email = Request.Cookies["UserInfoDemo"]["EmailDemo"].ToString();
                    TextBox1.Attributes.Add("value", email);

                    string pass = Request.Cookies["UserInfoDemo"]["PasswordDemo"].ToString();
                else if (HttpContext.Current.Request.Cookies["UserInfoDemo"] == null)
                    TextBox1.Text = "";

        protected void Button1_Click(object sender, EventArgs e)
            /* if login successfull */
            if (CheckBox1.Checked == true)
                /* Store Cookies into browser here at login time */
                /* Place into Coockies */
                //Creting a Cookie Object
                HttpCookie _userInfoCookies = new HttpCookie("UserInfoDemo");

                //Setting values inside it
                _userInfoCookies["EmailDemo"] = TextBox1.Text.Trim();
                _userInfoCookies["PasswordDemo"] = TextBox2.Text.Trim();
                //Adding Expire Time of cookies
                _userInfoCookies.Expires = DateTime.Now.AddDays(10);

                //Adding cookies to current web response

            /* do your operation */

Cookies,how to make Cookies in with C#.

Other related Post:


  1. cookies are used to personalize Web search engines (information).
    Many organizations and companies use ``cookies'' to track your every move on their site. Cookies, Session, and Application object are in for your informative article. Dot Net Training in chennai | dot net course fees


  2. Given so much information in it. its very useful .perfect explanation about Dot net framework.Thanks for your valuable information. dot net training in chennai velachery | dot net training institute in velachery