Asp.net官方标准控件实现用户的管理,虽然简单,但控件封装性很强,开发人员不能明白做了什么样的调用,还用别一方面,标准控件的使用,很大程度上限制了程序的可变性。如果自开发一整套用户管理系统,可行,但又失去了标准用户控件的作用,于是用API来管理用户,成为一个很好的先择,下面我列出主要(不 全部)的用户管理API实例:

1、注册用户
用Membership.CreateUser来创建设新用户,注意密友要包含一个符号,Membership位于System.Web.Security命名空间内。

//cs

       

 1Asp.net用户管理API的应用(上)try
 2

//Aspx代码

 1Asp.net用户管理API的应用(上)   <asp:Label ID="Label1" runat="server" Text="用户名:"></asp:Label>      
 2Asp.net用户管理API的应用(上)   <asp:TextBox ID="name" runat="server" Width="196px"></asp:TextBox>   
 3Asp.net用户管理API的应用(上)   <asp:Label ID="Label2" runat="server" Text="密码:"></asp:Label> 
 4Asp.net用户管理API的应用(上)   <asp:TextBox ID="password" runat="server" Width="197px"></asp:TextBox>  
 5Asp.net用户管理API的应用(上)   <asp:Label ID="Label3" runat="server" Text="确认密码:"></asp:Label>
 6Asp.net用户管理API的应用(上)   <asp:TextBox ID="OtherPass" runat="server" Width="196px"></asp:TextBox>     
 7Asp.net用户管理API的应用(上)   <asp:Label ID="Label4" runat="server" Text="电子邮件:"></asp:Label>  
 8Asp.net用户管理API的应用(上)   <asp:TextBox ID="email" runat="server" Width="193px"></asp:TextBox> 
 9Asp.net用户管理API的应用(上)   <asp:Label ID="Label5" runat="server" Text="安全提示问题:"></asp:Label>        
10Asp.net用户管理API的应用(上)   <asp:TextBox ID="question" runat="server" Width="189px"></asp:TextBox> 
11Asp.net用户管理API的应用(上)   <asp:Label ID="Label6" runat="server" Text="安全答案:"></asp:Label>  
12Asp.net用户管理API的应用(上)   <asp:TextBox ID="answer" runat="server" Width="187px"></asp:TextBox>      
13Asp.net用户管理API的应用(上)   <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="注册" Width="69px" />
14Asp.net用户管理API的应用(上)
15Asp.net用户管理API的应用(上)


  2、用户登录

用户登录用Membershi.ValidateUser来验证用户名和密码。如果通过验证,调用FormsAuthentication.RedirectFromLoginPage导向目标页面(这里以及后面的一些设置都是配合Forms验证展开,都预先在web.config中配置好Forms的验证策略)。
//cs代码,在登录按钮的单击事件注册的方法中

 1Asp.net用户管理API的应用(上)if (Membership.ValidateUser(UserName.Text,Password.Text))
 2


 //Aspx代码

 1Asp.net用户管理API的应用(上)<asp:Label ID="Label1" runat="server" Text="用户名:"></asp:Label>
 2Asp.net用户管理API的应用(上) <asp:TextBox ID="UserNmae" runat="server"></asp:TextBox>
 3Asp.net用户管理API的应用(上) <asp:Label ID="Label2" runat="server" Text="密码:"></asp:Label>
 4Asp.net用户管理API的应用(上) <asp:TextBox ID="Password" runat="server"></asp:TextBox>
 5Asp.net用户管理API的应用(上) <asp:Button ID="Login_But" runat="server" onclick="Button1_Click" Text="登录" 
 6Asp.net用户管理API的应用(上)   Width="69px" />
 7Asp.net用户管理API的应用(上) <asp:HyperLink ID="FindPass_HL" runat="server" NavigateUrl="~/FindPassword.aspx">忘记密码</asp:HyperLink>
 8Asp.net用户管理API的应用(上)<asp:HyperLink ID="Reg_HL" runat="server" NavigateUrl="~/register.aspx">注册</asp:HyperLink>
 9Asp.net用户管理API的应用(上)  
10Asp.net用户管理API的应用(上)
11Asp.net用户管理API的应用(上)


  3、找回密码

//cs

Cs中的邮件发方法,关于一些邮件的配置是在web.confing中存放,方法中有相关的获取方法

 1Asp.net用户管理API的应用(上)using System;
 2Asp.net用户管理API的应用(上)using System.Collections;
 3Asp.net用户管理API的应用(上)using System.Configuration;
 4Asp.net用户管理API的应用(上)using System.Data;
 5Asp.net用户管理API的应用(上)using System.Web;
 6Asp.net用户管理API的应用(上)using System.Web.Security;
 7Asp.net用户管理API的应用(上)using System.Web.UI;
 8Asp.net用户管理API的应用(上)using System.Web.UI.HtmlControls;
 9Asp.net用户管理API的应用(上)using System.Web.UI.WebControls;
10Asp.net用户管理API的应用(上)using System.Web.UI.WebControls.WebParts;
11Asp.net用户管理API的应用(上)using System.Web.Configuration;
12Asp.net用户管理API的应用(上)using System.Net.Configuration;
13Asp.net用户管理API的应用(上)using System.Net.Mail ;
14Asp.net用户管理API的应用(上)public partial class FindPassword : System.Web.UI.Page
15


//Aspx代码

 1Asp.net用户管理API的应用(上)<asp:Wizard ID="Wizard1" runat="server" ActiveStepIndex="2" 
 2Asp.net用户管理API的应用(上)        DisplaySideBar="False" Height="103px" 
 3Asp.net用户管理API的应用(上)        onfinishbuttonclick="Wizard1_FinishButtonClick" 
 4Asp.net用户管理API的应用(上)        onnextbuttonclick="Wizard1_NextButtonClick" Width="168px">
 5Asp.net用户管理API的应用(上)        <WizardSteps>
 6Asp.net用户管理API的应用(上)            <asp:WizardStep runat="server" title="用户名">
 7Asp.net用户管理API的应用(上)                请输入用户名:<br />
 8Asp.net用户管理API的应用(上)                <asp:TextBox ID=" Quest_TB" runat="server" Width="141px"></asp:TextBox>
 9Asp.net用户管理API的应用(上)            </asp:WizardStep>
10Asp.net用户管理API的应用(上)            <asp:WizardStep runat="server" title="问题">
11Asp.net用户管理API的应用(上)                <asp:Label ID="Label1" runat="server" Text="问题是:"></asp:Label>
12Asp.net用户管理API的应用(上)                <br />
13Asp.net用户管理API的应用(上)                <asp:Label ID="Label2" runat="server" Text="问题:"></asp:Label>
14Asp.net用户管理API的应用(上)                <br />
15Asp.net用户管理API的应用(上)                <asp:TextBox ID="Answer_TB" runat="server" Width="161px"></asp:TextBox>
16Asp.net用户管理API的应用(上)                <br />
17Asp.net用户管理API的应用(上)            </asp:WizardStep>
18Asp.net用户管理API的应用(上)            <asp:WizardStep runat="server" Title="完成">
19Asp.net用户管理API的应用(上)                <asp:Label ID="Label3" runat="server" Text="修改密码完成!"></asp:Label>
20Asp.net用户管理API的应用(上)            </asp:WizardStep>
21Asp.net用户管理API的应用(上)        </WizardSteps>
22Asp.net用户管理API的应用(上)</asp:Wizard>   
23Asp.net用户管理API的应用(上)//web.config中的配置
24Asp.net用户管理API的应用(上)位于configuration标签中
25Asp.net用户管理API的应用(上)<system.net>
26Asp.net用户管理API的应用(上)      <mailSettings>
27Asp.net用户管理API的应用(上)          <smtp from="axzxs2001@163.com">
28Asp.net用户管理API的应用(上)              <network host="smtp.163.com" password="*********" userName="axzxs2001" />
29Asp.net用户管理API的应用(上)          </smtp>
30Asp.net用户管理API的应用(上)      </mailSettings>
31Asp.net用户管理API的应用(上)  </system.net>
32Asp.net用户管理API的应用(上)

还有一此用户管理的API,在下一篇文章中叙述。

相关文章:

  • 2022-12-23
  • 2021-10-29
  • 2022-01-25
  • 2021-10-24
  • 2021-07-26
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-09-14
  • 2022-01-03
  • 2021-07-09
  • 2021-05-20
  • 2022-12-23
  • 2021-04-03
相关资源
相似解决方案