定义和使用ASP.NET Profile(附例)
1、双击一个数据源控件,将要存储profile的数据库作为数据源加入控件(这个步骤没什么用,只是为了方便大家用控件建立连接,这样不容易出错),建立好之后将design页面的数据源控件删除,你会发现在web.config里还是有一条连接语句,不要删除,我们下面将用到它,如: <connectionStrings>
<add name="aspnetdbConnectionString" connectionString="Data Source=JAMESSHENG;Initial Catalog=aspnetdb;Integrated Security=True" providerName="System.Data.SqlClient"/>
</connectionStrings>
2、定义Profile,在源码中加入
<profile enabled="true" automaticSaveEnabled="true" defaultProvider="SqlProvider">
<providers>
<clear/>
<add name="sqlProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="aspnetdbConnectionString" applicationName="ProfileSample" description="Sample for asp.net Profile and Profile Service"/>
</providers>
<properties>
<add name="BackGroudColor" type="System.String" allowAnonymous="true"/>
</properties>
</profile>
<anonymousIdentification enabled="true"/>
//defaultprovider指定默认配置文件提供程序的名称
automaticSaveEnabled指定用户配置文件是否在 ASP.NET 页执行结束时自动保存。如果为true,则用户配置文件在 ASP.NET 页执行结束时自动保存。
providers(可选元素)定义配置文件提供程序的集合,它当中包含<add> :name = defaultProvider的值;type = System.Web.Profile.SqlProfileProvider是使用sql;connectionStringName = aspnetdbConnectionString使用上面连接中定义的连接字符串;
properties(必选的元素)定义用户配置文件属性和属性组的集合,它当中包含<add>:name=“BackGroudColor”定义Profile中的属性名称;type="System.String"字符串类型;allowAnonymous="true"定义是否保存匿名用户配置,如果在此处定义true,则在后面必须加入<anonymousIdentification>配置,设
相关文档:
CTRL + SHIFT + B生成解决方案
CTRL + F7 生成编译
CTRL + O 打开文件
CTRL + SHIFT + O打开项目
CTRL + SHIFT + C显示类视图窗口
F4 显示属性窗口
SHIFT + F4显示项目属性窗口
CTRL + SHIFT + E显示资源视图
F12 转到定义
CTRL + F12转到声明
CTRL + ALT + J对象浏览
CTRL + ALT + F1帮助目录
CTR ......
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ViewState["BackUrl"] = Request.UrlReferrer.ToString();
}
}
/// <summary>
/// 返回按钮点击事件
/// </summary& ......
数据绑定控件比较(Reapter\DataList\GridView\DatailsView\FormView):
1.插入功能方面:
DetailsView和FormView具有插入功能,其它控件没有
2.模板
DataList\FormView\Repeater三种必须编辑模板,而
GridView和DetailsView只有在将列转换成模板列以后才会出现各种模板.
3.自动分页功能
GridView ,DetailsView和FormView ......
1. 适当使用UpdatePanel
2. 利用WebService方法动态生成用户控件的内容,避免UpdatePanel回传造成的性能损失(ViewState)
3. ToolkitScriptManager代替ScriptManager
4. <asp:ScriptManager runat="server" ID="sm" ScriptMode="Release" EnablePartialRendering="false"
......
新建一个默认的ASP.NET MVC2应用程序,系统会默认的生成包含基本功能的应用程序,查看这些生成的代码,可帮助我们理解ASP.NET MVC2。下面是对URL路由的理解,以备忘。
一、Global.asax.cs中的代码:
public class MvcApplication : System.Web.HttpApplication
{
&n ......