使用credentials节点建立会员系统

做科室网站............

之前以为只有一个管理员使用。

就没有设计会员系统。

直接把admin用户放在了credentials节点下....

做完之后。又被告知需要下级单位上传资料。也需要用户名密码。

考虑到不是对外注册且改动性非常小....

就直接还是在credentials节点下保持用户名密码即可。

P.S.由于只内网使用.........直接clear  PasswordFormat了..........

->添加新用户

    protected void btnRegister_Click(object sender, EventArgs e)
    {
        FormsAuthenticationUser user = new FormsAuthenticationUser(userName.Text, password.Text);
        Configuration configuration = WebConfigurationManager.OpenWebConfiguration("/");
        ((AuthenticationSection)configuration.GetSection("system.web/authentication")).Forms.Credentials.Users.Add(user);
        configuration.Save();
    }
 
创建FormsAuthenticationUser -> 打开web.config -> 定位到credential节点 -> 使用FormsAuthenticationUserCollection的Add方法添加用户 -> 保持web.config


->列表显示所有用户

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            rptUserList.DataSource = (WebConfigurationManager.GetWebApplicationSection("system.web/authentication") as AuthenticationSection).Forms.Credentials.Users;
            rptUserList.DataBind();
        }
        
    }
绑定集合FormsAuthenticationUserCollection


->删除用户

在上述列表显示用户中同事显示删除按钮

    protected void rptUserList_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        if (e.CommandName == "Delete")
        {
            string name = e.CommandArgument.ToString();
            Configuration configuration = WebConfigurationManager.OpenWebConfiguration("/");
            ((AuthenticationSection)configuration.GetSection("system.web/authentication")).Forms.Credentials.Users.Remove(name);
            configuration.Save();
            

        }
    }

-> 用户登录

     if (FormsAuthentication.Authenticate(tbName.Text,tbPassword.Text))
     {
           FormsAuthentication.RedirectFromLoginPage(tbName.Text, true);
     }





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值