ASP.NET网站开发--个性化用户配置
程序员文章站
2024-03-25 21:17:58
...
1.<Profille>配置节
设置<Profille>配置节经常对其三部分进行设置:
1.<Profille>自身属性;
2.子节<properties>属性设置
3.子节<providers>属性设置
例:
<profile enabled="true" defaultProvider="AspProfileProvider">
<providers>
<clear/>
<add name="AspProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="aspnetdbConnectionString"/>
</providers>
<properties>
<add name="usename" allowAnonymous="true"/>
<add name="userpwd" allowAnonymous="true"/>
<add name="birthday" type="System.DateTime"/>
</properties>
</profile>
1.1实例
Addprofile.aspx页面:
<body>
<form id="form1" runat="server">
<div>
Nick Name:<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
UserPwd:<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<br />
Birthday:<asp:Calendar ID="Calendar1" runat="server"></asp:Calendar>
<br />
<asp:Button ID="Button1" runat="server" Text="保存设置" onclick="Button1_Click" />
</div>
</form>
</body>
按钮“保存设置”后台单击事件:
protected void Button1_Click(object sender, EventArgs e)
{
if (!Profile.IsAnonymous)
{
Profile.usename = TextBox1.Text;
Profile.userpwd = TextBox2.Text;
Profile.birthday = Calendar1.SelectedDate;
Response.Redirect("Default.aspx");
}
else
{
Profile.usename = TextBox1.Text;
Profile.userpwd = TextBox2.Text;
Response.Redirect("Default.aspx");
}
}
Default.aspx.cs页面:
protected void Page_Load(object sender, EventArgs e)
{
Response.Write("昵称:" + Profile.usename + "<br/>密码:" + Profile.userpwd + "<br/>生日:"+Profile.birthday.ToLongDateString());
}
Login.aspx页面:
<body>
<form id="form1" runat="server">
<div>
<asp:Login ID="Login1" runat="server" DestinationPageUrl="Welcome.aspx" >
</asp:Login>
</div>
</form>
</body>
Welcome.aspx页面:
<body>
<form id="form1" runat="server">
<div>
<asp:LoginView ID="LoginView1" runat="server">
<AnonymousTemplate>
<a href="Default.aspx">查看个性化设置</a>
<a href="Addprofile.aspx">添加个性化需求</a>
</AnonymousTemplate>
<LoggedInTemplate>
欢迎:<asp:LoginName ID="LoginName1" runat="server" />
!!!<br/>
<a href="Default.aspx">查看个性化设置</a>
<a href="Addprofile.aspx">添加个性化需求</a>
</LoggedInTemplate>
</asp:LoginView>
</div>
</form>
</body>
web配置文件页:
<profile enabled="true" defaultProvider="AspProfileProvider">
<providers>
<clear/>
<add name="AspProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="aspnetdbConnectionString"/>
</providers>
<properties>
<add name="usename" allowAnonymous="true"/>
<add name="userpwd" allowAnonymous="true"/>
<add name="birthday" type="System.DateTime"/>
</properties>
</profile>
web配置文件页中的:
<connectionStrings>
<add name="aspnetdbConnectionString" connectionString="Data Source=.;Initial Catalog=aspnetdb;Integrated Security=True" providerName="System.Data.SqlClient"/>
</connectionStrings>
是连接数据库,并且使用控件绑定数据库所得;(使用后控件可以删除)
推荐阅读
-
ASP.NET——个性化配置
-
ASP.NET网站开发--个性化用户配置
-
ASP.NET网站开发:个性化用配置
-
ASP.NET网站开发--用户控件与HttpHandler
-
转载: 10年老程序员谈Dotnet程序员职业规划(图文) asp.net网站开发c#
-
ASP.net网站性能提高办法 无意中从网上浏览到了一篇提高网站性能的帖子转来学习下。 博客分类: asp.net开发ASP.net网站性能提高办法 asp.net多线程
-
ASP.NET界面开发环境配置,看看你的VS、SQL是否正确对应 DevExpressASP.NET.NET FrameworkSQL
-
asp.net网站开发包wq.dll打包下载
-
asp.net网站开发包wq.dll打包下载
-
ASP.NET 网站开发中常用到的广告效果代码