普通用户视图
v这是普通用户登陆,可以修改密码与邮件。
v使用MembershipUser user = Membership.GetUser(userName);获取成员用户
v修改密码使用user.ChangePassword(oldPassword, newPassword);方法,获取老密码使用string oldPassword = user.GetPassword();注意:web.config里的<membership>里的要为requiresQuestionAndAnswer=“false”。
v电子邮件修改使用user.Email = email;Membership.UpdateUser(user);方式修改。
普通用户视图代码
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;
namespace RegeditOfAdoDotnet
{
public partial class GeneralUserInfo : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//清除缓存
Response.Buffer = true;
Response.ExpiresAbsolute = System.DateTime.Now.AddSeconds(-1);
Response.Expires = 0;
Response.CacheControl = "no-cache";
Response.AddHeader("Pragma", "No-Cache");
//获取登陆用户名
lblUserName.Text = HttpContext.Current.User.Identity.Name;
}
/// <summary>
/// 确定
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnConfirm_Click(object sender, EventArgs e)
{
if (Page.IsValid)
{
try
{
MembershipUser user = Membership.GetUser(lblUserName.Text);//获取当前用户
string oldPassWord = user.GetPassword();//获取当前用户密码
if (!string.IsNullOrEmpty(txtPassWord.Text.ToString()))
{
string newPassWord = txtPassWord.Text.ToString();//获取新密码
user.ChangePassword(oldPassWord, newPassWord);//修改密码
}
if (!string.IsNullOrEmpty(txtEmail.Text.ToString()))
{
user.Email = txtEmail.Text.ToString();//获取新邮箱
}
Membership.UpdateUser(user);//更新当前用户注册信息
}
catch (Exception exp)
{
Response.Write(exp.Message); //输出错误信息
}
finally
{
ClientScript.RegisterStartupScript(this.GetType(), "myscript", "<script>alert('修改成功!');</script>");
}
}
}
/// <summary>
/// 清空
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnClear_Click(object sender, EventArgs e)
{
Response.Redirect("~/Admin/GeneralUserInfo.aspx");
}
}
}