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
相关文档:
在Web编程过程中,存在着很多安全隐患。比如在以前的ASP版本中,Cookie为访问者和编程者都提供了方便,并没有提供加密的功能。打开IE浏览器,选择“工具”菜单里的“Internet选项”,然后在弹出的对话框里单击“设置”按钮,选择“查看文件”按钮,在弹出的窗口中,就会显示硬盘里 ......
数据绑定控件比较
(Reapter\DataList\GridView\DatailsView\FormView):
1.插入功能方面:
DetailsView和FormView具有插入功能,其它控件没有
2.模板
DataList\FormView\Repeater三种必须编辑模板,而
GridView和DetailsView只有在将列转换成模板列以后才会出现各种模板.
3.自动分页功能
GridView ,DetailsView和Form ......
ASP.NET文件下载函数使用是什么情况呢?在你的Page_Load中添加这样的代码:
Page.Response.Clear();
bool success = ResponseFile(Page.Request, Page.Response, "目的文件名称", @"源文件路径", 1024000);
if (!success) Response.Write("下载文件出错!"); Page.Response.End();
ASP.NET文件下载函数代码为:
publi ......
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.web>
<!-- 动态调试编译
设置 compilation debug="true" 以将调试符号(.pdb 信息)插入到编译页中。因为这将创建执行起来较慢的大文件,所以应该只在调试时将该值设置为 true,而所有其他时候都设置为false。有关更多信息, ......
前面介绍过了如何使用Forms方式进行用户身份验证,然而,在大多网站中都会有一个“退出”功能,让用户可以通出登录。在asp.net中,退出的方式很简单,只要在退出页面中加上代码“FormsAuthentication.SignOut()”即可。
你可以使用Response.Redirect()在退出之 ......