- 浏览: 424294 次
- 性别:
- 来自: 唐山
文章分类
最新评论
-
hautbbs:
谢谢分享!
ASP.NET 导出Excel 和csv -
hautbbs:
感谢分享!
ASP.NET 导出Excel乱码的终极解决 -
wyf:
zcl920 写道只能说 看不懂。要发就发全 取一段出来 有什 ...
图片上绘制文字换行处理 -
zcl920:
只能说 看不懂。要发就发全 取一段出来 有什么用。
图片上绘制文字换行处理 -
380086154:
有用,谢谢。
js比较日期
介绍
ASP.NET 2.0 中的存储用户配置功能使您可以定义并存储要在整个应用程序中使用的基于用户的设置。而且,在用户未登录时,可以将这些设置存储在匿名配置文件中,然后在将来某个时间将其迁移到登录用户的配置文件中。
关键
1、配置<system.web>元素下的<profile>元素;如果需要支持匿名的话则还需要配置<system.web>元素下的<anonymousIdentification>元素。示例如下,仅为说明
<profile enabled="true" defaultProvider="SqlProfileProvider" inherits="CustomProfile"> <providers> <add name="SqlProfileProvider" type="System.Web.Profile.SqlProfileProvider, System.Web, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="SqlConnectionString" applicationName="/" /> </providers> <properties> <add name="Name" /> <add name="Color" type="System.Drawing.Color" /> <group name="Group"> <add name="Collection" type="System.Collections.ArrayList" /> <add name="Price" type="int" defaultValue="100" /> </group> </properties> </profile> <anonymousIdentification enabled="true" cookieName=".VS2005_ANONYMOUS" cookieTimeout="1440" cookiePath="/" cookieRequireSSL="false" cookieSlidingExpiration="true" cookieProtection="All" cookieless="UseCookies" />各属性详细说明参看MSDN,索引处查找“profile 元素”和“anonymousIdentification 元素”
注意:
<profile>元素的inherits属性指定自定义类,该类要继承自ProfileBase
Profile是自动保存的,但是某些复杂类型可能无法自动保存,此时需要设置<profile>元素的automaticSaveEnabled设置为false,要保存的话则调用 Profile 上的 Save 方法即可。要动态取消Profile的自动保存功能的话则需要在 global.asax 中加一个Profile_ProfileAutoSaving事件,示例如下,仅为说明
void Profile_ProfileAutoSaving(Object sender, ProfileAutoSaveEventArgs e) { if ((e.Context.Items["CancelProfileAutoSave"] != null) && ((bool)e.Context.Items["CancelProfileAutoSave"] == true)) e.ContinueWithProfileAutoSave = false; }
在需要取消Profile的自动保存功能的页的代码处如下写
protected void Page_Load(object sender, EventArgs e) { Context.Items["CancelProfileAutoSave"] = true; }2、通过ProfileManager执行相关任务,如搜索有关所有配置文件、经过身份验证用户的配置文件及匿名用户的配置文件的统计信息,确定在给定时间段内尚未修改的配置文件的数量,根据配置文件的上一次修改日期删除单个配置文件及多个配置文件等
3、将匿名配置文件迁移到经过身份验证的配置文件
在global.asax加一个Profile_MigrateAnonymous事件处理,示例如下,仅为说明
void Profile_MigrateAnonymous(Object sender, ProfileMigrateEventArgs pe) { // 获得匿名配置 ProfileCommon anonProfile = Profile.GetProfile(pe.AnonymousID); // 从匿名配置中取值并赋值给经过身份验证的配置 if (anonProfile.Color != System.Drawing.Color.Empty) { Profile.Color = anonProfile.Color; } // 从数据库中删除匿名配置 ProfileManager.DeleteProfile(pe.AnonymousID); // 清除与某个会话关联的匿名 Cookie 或标识符 AnonymousIdentificationModule.ClearAnonymousIdentifier(); }示例
App_Code/CustomProfile.cs
using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Web.Profile; /// <summary> /// CustomProfile 的摘要说明 /// </summary> public class CustomProfile : ProfileBase { private string _customName; public string CustomName { get { return (string)base["CustomName"]; } set { base["CustomName"] = value; } } private bool _customSex; public bool CustomSex { get { return (bool)base["CustomSex"]; } set { base["CustomSex"] = value; } } }
web.config
<profile enabled="true" defaultProvider="SqlProfileProvider" inherits="CustomProfile"> <providers> <add name="SqlProfileProvider" type="System.Web.Profile.SqlProfileProvider, System.Web, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="SqlConnectionString" applicationName="/" /> </providers> <properties> <add name="Name" /> <add name="Color" type="System.Drawing.Color" /> <group name="Group"> <add name="Collection" type="System.Collections.ArrayList" /> <add name="Price" type="int" defaultValue="100" /> </group> </properties> </profile>
Profile/Test.aspx
<%@ Page Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="Test.aspx.cs" Inherits="Profile_Test" Title="存储用户配置测试" %> <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server"> <asp:Label ID="lbl" runat="Server" /> </asp:Content>
Profile/Test.aspx.cs
using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; public partial class Profile_Test : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { // 一看就懂 Profile.Name = User.Identity.Name; Profile.Color = System.Drawing.Color.AliceBlue; Profile.Group.Collection.Clear(); Profile.Group.Collection.Add("冰棍"); Profile.Group.Collection.Add("瓜子"); Profile.Group.Price = 999999; Profile.CustomName = User.Identity.Name; Profile.CustomSex = true; lbl.Text = "Name:" + Profile.Name + "<br />"; lbl.Text += "Color:" + Profile.Color.ToString() + "<br />"; foreach (string s in Profile.Group.Collection) { lbl.Text += "商品有:" + s + "<br />"; } lbl.Text += "价格:" + Profile.Group.Price + "<br />"; lbl.Text += "自定义类名字:" + Profile.CustomName + "<br />"; lbl.Text += "自定义类姓名:" + Profile.CustomSex; } }用“abc”这个用户登录后的运行结果
Name:abc
Color:Color [AliceBlue]
商品有:冰棍
商品有:瓜子
价格:999999
自定义类名字:abc
自定义类姓名:True
注:需要用aspnet_regsql配置数据库
发表评论
-
登录时记住用户名密码的实现方式
2019-06-12 15:11 2954登录的时候记住用户 ... -
CAS 实现单点登录 .NET MVC
2016-05-24 17:14 1066http://www.cnblogs.com/woxpp/p ... -
.NET开发邮件发送功能的全面教程(含邮件组件源码)
2015-03-31 09:43 1085原文地址:http://www.cnblogs.com/he ... -
开发Web组合
2015-01-04 11:39 5781、数据库操作 ORM-Dapper 2、前台界面布局采 ... -
基于 Bootstrap 构建的网站
2014-12-14 14:12 601文档,下载地址:http://v3.bootcss.com ... -
iis8 默认不支持svc解决方法
2014-09-18 18:57 722以下内容对于使用WIN2012 部署V9的时候使用。 ... -
C# 连接Oracle(利用ODP.net,不安装oracle客户端)
2014-07-11 09:37 1654C# 连接Oracle(利用ODP.net,不安装oracl ... -
C# Attribute 特性,过期特性
2014-05-27 15:18 1771通过下列过程将属性应用到代码元素。 通过从 .NE ... -
.NET画实时直方图
2011-12-30 09:37 867using System; using System.Col ... -
设置combobx选中项
2011-12-21 15:20 998cbRole.SelectedIndex = cbRole.I ... -
文档树状结构化目录管理方法
2011-12-20 09:50 2088本文适用于附件(各类文档、图片和压缩包等,下同)比较多的 ... -
.StringTemplate替换模板
2011-11-03 10:19 1209官方下载 www.StringTemplate. ... -
WCF-IErrorHandler
2011-10-11 16:30 1001使用 IErrorHandler 接口,我们可以更深入地 ... -
ADODB.Stream instead of Scripting.FileSystemObject.
2011-07-04 08:55 1214In a Silverlight 4 OOB App (eve ... -
Scripting.FileSystemObject对象的详细技巧指南
2011-07-03 23:39 1012Scripting.FileSystemObject对象的 ... -
Stream 和 byte[] 之间的转换
2011-07-02 16:52 1038/* - - - - - - - - - - - - - ... -
常用正则表达式
2011-06-15 20:17 762正则表达式用于字符 ... -
DynamicMethod 类
2011-05-11 22:51 1114public delegate String MyMetho ... -
一个通用的快速反射方法(A General Fast Method Invoker)
2011-04-13 22:01 1488普通反射方法 MethodInfo methodIn ... -
C#操作IIS(转)可以写一个工具自己配置网站
2011-03-24 21:08 2232using System; using System.Dir ...
相关推荐
Programming Microsoft ASP.NET 2.0 Applications - Advanced Topics
是一个不可多得的实例网站代码 利用的三层架构开发的B/S结构的 购物网站实例,值得参考
原装的英文版Asp.net2.0 入门经典C#篇.避免了翻译后的质量下降
ASP.NET第一步:基于C#和ASP.NET 2.0---配套源码大全 附带了很多整理好的知识点, 很实用
Asp.Net2.0读取-修改-新增(配置文件web.config)可以是 ***.config里面有3个文件操作类,System.config,使用文档
Apress pro asp.net 2.0 e-commerce
CrystalReports2.0--Asp.net2.0水晶报表(CrystalReports)实例源码大全(C#).rar
ASP.NET 2.0动态网站开发基础教程(C#) 第01章 ASP.NET2.0基础 Framework Web Form(共32页).ppt ASP.NET 2.0动态网站开发基础教程(C#) 第02章 HTML和脚本语言 VBScript javaScript(共21页).ppt ASP.NET 2.0...
光盘内容。购买地址:http://auction1.taobao.com/auction/item_detail-0db2-ccd1e4fe3437e6c93a1aa122bdd94c47.jhtml
在线考试系统 Asp.net2.0 c# 在线考试系统 Asp.net2.0 c# 在线考试系统 Asp.net2.0 c# 在线考试系统 Asp.net2.0 c# 在线考试系统 Asp.net2.0 c#
这部分内容不需要读者有任何的客户端开发知识,只要在Visual Stuio中轻松拖放即可实现强大的客户端Ajax功能,例如局部页面更新、异步回送、拖放、动画等,非常适合为现有的ASP.NET 2.0应用程序添加少量的Ajax特性,...
接下来介绍了.NET中Web页面设计的基础知识和ASP.NET2.0服务器端控件的使用方法;作为ASP.NET数据库开发的准备内容,本书也介绍了些SQL语言的基础知识。此外,还介绍了ASP.NET中的常用对象、数据访问技术、数据源控件...
内容代码,使用VB.net和C# 两种解释 <br>第1章ASP.NET2.0概述 1 1.1简史 1 1.2ASP.NET2.0的目标 2 1.2.1开发人员的效率 3 1.2.2管理 5 1.2.3性能和可伸缩性 8 1.3ASP.NET2.0的其他新特性 8 ...
《ASP.NET 2.0 入门经典》将逐步引导您使用 ASP.NET 2.0 创建动态的、数据驱动的、复杂的Web站点。在本章结束时,我们将解释一些基本的想法并介绍一个完整的示例站点。然后将学习怎样使用 Visual Web Developer ...
在全面介绍ASP.NET各种编程技能的同时重点介绍了ASP.NET 2.0版本中的巨大变化,详细阐述了ASP.NET 2.0中所包含的每个新特性。书中提供了大量的实例,可帮助读者快速掌握如何在.NET Framework下构建功能强大的ASP.NET...
asp.net2.0实例开发实例:在线考试系统
ASP.NET2.0实用教程(C#版)书中例子,这是一个PPT的
本书通过深入剖析12个使用ASP.NET 2.0开发的项目,全面阐述了ASP.NET 2.0应用程序的架构及ASP.NET 2.0新增的控件和功能。通过探索这些项目的设计和代码,读者可快速掌握使用ASP.NET 2.0开发应用程序的技巧,从空白...
Using code examples in C#, this invaluable beginner's guide shows you how to program web applications in ASP.NET 2.0 and see dynamic results with minimal effort. Through detailed explanations and ...