×Welcome aboard! We are happy you are here and wish you good net-raft!



Together We Can Simplify The World

the current number of solutions:  2379
.htaccess (1x)    AJAX (13x)    ANGULARJS (161x)    ASP (1x)    ASP.NET (6x)    BACKBONE.JS (47x)    BOOTSTRAP (12x)    C# (226x)    COFFEESCRIPT (28x)    CSS (71x)    HTML (47x)    JADE (34x)    JAVA (51x)    JAVASCRIPT (432x)    JQUERY (395x)    JQUERY MOBILE (5x)    JSON (5x)    LARAVEL (27x)    MYSQL (9x)    NODEJS (162x)    ORACLE SQL (19x)    PERL (2x)    PHP (302x)    PYTHON (10x)    REACT (62x)    RUBY (25x)    RUBY ON RAILS (1x)    SHELL (2x)    SQL (90x)    SQL SERVER (3x)    TYPESCRIPT (51x)    VB.NET (33x)    W3.CSS (6x)    W3.JS (40x)    
join us

click to create your account

set cookie value c#

(c# set cookie value )

- C#

 viewed 8

Comment:
C#

0

<% @Page Language="C#" %>

<!-- code section -->
<script runat="server">

private void set_cookie(object sender, EventArgs e)
{

HttpCookie myCookie = new HttpCookie("MyTestCookie");
DateTime now = DateTime.Now;

// Set the cookie value.
myCookie.Value = now.ToString();
// Set the cookie expiration date.
myCookie.Expires = now.AddMinutes(1);

// Add the cookie.
Response.Cookies.Add(myCookie);

Response.Write("<p> The cookie has been written.");

}

private void read_cookie(object sender, EventArgs e)
{

HttpCookie myCookie = new HttpCookie("MyTestCookie");
myCookie = Request.Cookies["MyTestCookie"];

// Read the cookie information and display it.
if (myCookie != null)
Response.Write(myCookie.Value);
else
Response.Write("not found");

}

private void delete_cookie(object sender, EventArgs e)
{

HttpCookie myCookie = new HttpCookie("MyTestCookie");
DateTime now = DateTime.Now;

//To assign a past expiration date on a cookie
myCookie.Expires = now.AddMinutes(-1);

// Add the cookie.
Response.Cookies.Add(myCookie);

Response.Write("<p> The cookie has been deleted.");

}

</script>

<html>
<head>

</head>

<body>

<form runat="server">

<input runat="server" id="button1" type="submit" value="set cookie" OnServerClick="set_cookie"/>

<input runat="server" id="button2" type="submit" value="read cookie" OnServerClick="read_cookie"/>

<input runat="server" id="button3" type="submit" value="delete cookie" OnServerClick="delete_cookie"/>

<hr />

</form>

</body>
</html>

     

created: 5 months ago

The power of the user (%)

49%

Do you know a little more effective code ? Feel free to optimize ...


haven't you found what you're looking for ?
Write us your question ...
Login is not needed.


The most helpful C# solutions
Likes Solution Technology
719 detect ie C#C#
148 Get real client ip address using C# ?C#
135 get real user country C#C#
106 how to initialize a connection to mysql database using C# ?C#
106 get hostname using C#C#
44 get username using C#C#
42 get real user country code C#C#
39 how to detect the type of a browser using C# in asp.net ?C#
32 How to detect monitor or notebook using C# ?C#
28 get real user city C#C#
Check out all of C# ...
The most viewed C# solutions by country
Solution Country
Get real client latitude and longitude using C# ?Cinque Terre
How to get the latitude and longitude from ip address using C# in asp.net ?Cinque Terre
get current url using C#Cinque Terre
Get real client latitude and longitude using C# ?Cinque Terre
Get real client latitude and longitude using C# ?Cinque Terre
check if cookie exists c#Cinque Terre
get current url using C#Cinque Terre
Get real client latitude and longitude using C# ?Cinque Terre
how do I connect to mysql database using C# ?Cinque Terre
How to get the region name from ip address using C# in asp.net ?Cinque Terre