Skip to main content

What is Cookies?

Reference from :- http://www.c-sharpcorner.com/uploadfile/annathurai/cookies-in-Asp-Net/

Cookiesis a small piece of information stored on the client machine. This file is located on client machines "C:\Document and Settings\Currently_Login user\Cookie" path.  Its is used to store user preference information like Username, Password,City and PhoneNo etc on client machines. We need to import namespace called  Systen.Web.HttpCookie before we use cookie.
 
Type of Cookies?
  1. Persist Cookie - A cookie has not have expired time Which is called as Persist Cookie
  2. Non-Persist Cookie - A cookie has expired time Which is called as Non-Persist Cookie
How to create a cookie?
 
Its really easy to create a cookie in the Asp.Net with help of Response object or HttpCookie
 
Exp 1:
 
        HttpCookie userInfo = new HttpCookie("userInfo");
        userInfo[
"UserName"] = "Annathurai";
        userInfo[
"UserColor"] = "Black";
        userInfo.Expires.Add(
new TimeSpan(0, 1, 0));        Response.Cookies.Add(userInfo);Exp 2:
 
        Response.Cookies["userName"].Value = "Annathurai";        Response.Cookies["userColor"].Value = "Black";
                       
How to retrieve from cookie?
Its easy way to retrieve cookie value form cookes by help of Request object.
 
Exp 1:
 
        string User_Name = string.Empty;
       
string User_Color = string.Empty;
        User_Name = Request.Cookies[
"userName"].Value;        User_Color = Request.Cookies["userColor"].Value;Exp 2:
 
        string User_name = string.Empty;
       
string User_color = string.Empty;
       
HttpCookie reqCookies = Request.Cookies["userInfo"];
       
if (reqCookies != null)
        {
            User_name = reqCookies[
"UserName"].ToString();
            User_color = reqCookies[
"UserColor"].ToString();        }
 
When we make request from client to webserver
the web server process the request and give the lot of information with big pockets  which will have Header information, Metadata, cookies etc., Then repose object can do all the things with browser.

Comments

Popular posts from this blog

Spire.Office for .NET

Introduction Free Spire.Doc for .NET is a Community Edition of the Spire.Doc for .NET, which is a totally free word component for commercial and personal use. As a free C#/VB.NET component, it also offers a lot of powerful functions. Developers can use it to generate, read, write, save, print and convert documents on any .NET applications. The featured function, conversion allows converting Word documents (Word 97-2003, Word 2007, Word 2010, word 2013) to commonly used file format, such as XML, RTF, TXT, PDF, XPS, EPUB, HTML and Image etc. Visit Site for Details :-  Click Here to Visit Official Site     Click here to Download Tools :- Download Here In this article we are going to learn how to generate DOC file Use Powerful tool Spire.Office for .NET Tool Required We are using Visual Studio 2012. Free Spire.Office Component [Free for commercial and personal use] Support .Net from [ 2.0 to 4.5 ] Getting Started Let’s start with cre...

IList in C#

Lists and arrays implement IList. This interface is an abstraction that allows list types to be used with through a single reference type. Properties of IList Few popular property of IList interface is given below. Count:-  It will return number of object in List IsReadOnly:- This property will indicate whether the IList is read-only or not. Item:- It will return the particular Item of specified index. Example :-  For calling this class method in void Main. Final Output :-  

Capturing Image From Web Cam in ASP.Net MVC

This article shows how to capture an image using a webcam in MVC4 and in this application we will use a jQuery webcam.js plug-in for capturing images. I have seen that most online applications currently require webcam image capturing functionality in some way or another. Most social networking sites use this kind of functionality in their application for capturing user profile pictures. To see Complete Article Visit: -  http://www.c-sharpcorner.com/UploadFile/4d9083/capturing-image-from-web-cam-in-Asp-Net-mvc139/ Agenda Create basic MVC application. Download and Adding webcam.js related reference files to project. Adding Controller ( PhotoController ). Adding Index view. Adding Action Method Capture( ). Adding Script for capturing Image. Adding Action Method and Script for binding image. Adding [HttpPost] Index Action Method. Displaying the index View in New Window. Changephoto.cshtml Code Snippet. PhotoController Code Snippet. Index.cshtml Code ...