asp.net下Cookie的使用简单示例
//第一种方式
Response.Cookie("Cookie名称").value="值" //写入
username=Request.Cookies("Cookie名称").value// 读取
//第二种方式
HttpCookie hcCookic = new HttpCookie("Cookie名称","值");
Response.Cookies.Add(hcCookic);
C# :
//方法1:
Response.Cookies["username"].Value="gjy";
Response.Cookies["username"].Expires=DateTime.Now.AddDays(1);
//方法2:
System.Web.HttpCookie newcookie=new HttpCookie("username");
newcookie.Value="gjy";
newcookie.Expires=DateTime.Now.AddDays(1);
Response.AppendCookie(newcookie);
//创建带有子键的cookies:
System.Web.HttpCookie newcookie=new HttpCookie("user");
newcookie.Values["username"]="gjy";
newcookie.Values["password"]="111";
newcookie.Expires=DateTime.Now.AddDays(1);
Response.AppendCookie(newcookie);
//cookies的读取:
//无子键读取:
if(Request.Cookies["username"]!=null)
{
Response.Write(Server.HtmlEncode(Request.Cookies["username"].Value));
}
//有子键读取:
if(Request.Cookies["user"]!=null)
{
Response.Write(Server.HtmlEncode(Request.Cookies["user"]["username"].Value));
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/carlfan/archive/2009/08/12/4440284.aspx
相关文档:
此处提供的代码用来实现当asp.net页面中的某个Button被点击后disable掉该页面中所有的Button,从而防止提交延时导致的多次提交。基于之前的onceclickbutton脚本.
//ASP.NET中防止页面多次提交的代码:javascript< script language="javascript"> < !-- function disableOtherSubmit() {
var obj = event.srcElem ......
添加一个类:把下面的文件放在类中就可以了。
using System;
using System.Web;
using System.Data;
using System.Data.SqlClient;
public class MessageBox
{
public MessageBox()
{
& ......
string filepath = FileUpload1.FileName; &nb ......
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.web>
<!-- 动态调试编译
设置 compilation debug="true" 以将调试符号(.pdb 信息)插入到编译页中。因为这将创建执行起来较慢的大文件,所以应该只在调试时将该值设置为 true,而所有其他时候都设置为false。有关更多信息, ......
在前面的几篇文章中介绍了asp.net的窗体身份验证,这种身份验证方式可以让通过验证的用户访问指定的目录,而没有通过验证的用户不能访问该目录下的网页。
但是,有一种例外,就是目录中的html文件例外。例如,在《asp.net中的窗体身份验证(最简单篇)》中介绍的,除了登录网页之外 ......