Cache Object Cookie object (ASP. NET technology)

Source: Internet
Author: User

The realization remembers the password, the expiration date and so on function. Cookies.

The Expires property and the Value property of the cookie object.

/////////////////////////////////////////////////////////////////////////////////////////////////////

Using System;

Using System.Collections;

Using System.Configuration;

Using System.Data;

Using System.Linq;

Using System.Web;

Using System.Web.Security;

Using System.Web.UI;

Using System.Web.UI.HtmlControls;

Using System.Web.UI.WebControls;

Using System.Web.UI.WebControls.WebParts;

Using System.Xml.Linq;

public partial class Admin:System.Web.UI.Page

{

protected void Page_Load (object sender, EventArgs e)

{

if (session["username"] = = null)

{

Response.Redirect ("default.aspx");

}

Else

{

Response.Write ("codego.net" + session["username"] + "Successful login! ");

}

}

}

///////////////////////////////////////////////////////////////////////////

Using System;

Using System.Configuration;

Using System.Data;

Using System.Linq;

Using System.Web;

Using System.Web.Security;

Using System.Web.UI;

Using System.Web.UI.HtmlControls;

Using System.Web.UI.WebControls;

Using System.Web.UI.WebControls.WebParts;

Using System.Xml.Linq;

public partial class _default:system.web.ui.page

{

protected void Page_Load (object sender, EventArgs e)

{

}

protected void button2_click (object sender, EventArgs e)

{

Txtname. Text = "";

Txtpwd. Text = "";

}

protected void Button1_Click (object sender, EventArgs e)

{

if (txtname. Text.trim (). Equals ("Mr") && txtpwd. Text.trim (). Equals ("Mrsoft"))

{

session["username"] = txtname. Text.trim ();

if (Ckbauto. Checked)

{

if (request.cookies["username"] = = null)

{

response.cookies["username"]. Expires = DateTime.Now.AddDays (30);

response.cookies["Userpwd"]. Expires = DateTime.Now.AddDays (30);

response.cookies["username"]. Value = txtname. Text.trim ();

response.cookies["Userpwd"]. Value = Txtpwd. Text.trim ();

}

}

Response.Redirect ("admin.aspx");

}

Else

{

Clientscript.registerstartupscript (this. GetType (), "", "alert (' Username or password error! '); ", true);

}

}

protected void Txtname_textchanged (object sender, EventArgs e)

{

if (request.cookies["username"]! = NULL)

{

if (request.cookies["username"]. Value.equals (txtname. Text.trim ()))

{

Txtpwd. attributes["value"] = request.cookies["Userpwd"]. Value;

}

}

}

}

This article is from the "Zhutousandebokezhijia" blog, make sure to keep this source http://9529231.blog.51cto.com/9519231/1571111

Cache Object Cookie object (ASP. NET technology)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.