我正在开发一个MVC webapp,并完成了使用SQL Membership表的注册模块。
现在,我编写了一些代码,当用户创建并获得批准后,应用程序会向用户发送一封电子邮件中的激活链接。
现在我想创建一个管理员页面,管理员可以批准这些注册用户
我该怎么做?
代码:
public ActionResult Register(RegisterModel model)
{
if (ModelState.IsValid)
{
// Attempt to register the user
MembershipCreateStatus createStatus = MembershipService.CreateUser(model.UserName, model.Password, model.Email);
if (createStatus == MembershipCreateStatus.Success)
{
// FormsService.SignIn(model.UserName, false /* createPersistentCookie */);
//used profiler -- add profile information
var profile = Profile.GetProfile(model.UserName);
profile.FirstName = model.FirstName;
profile.LastName = model.LastName;
profile.Save();
//email confirmation code
MembershipService.SendConfirmationEmail(model.UserName);
return RedirectToAction("Confirmation");
}
else
{
ModelState.AddModelError("", AccountValidation.ErrorCodeToString(createStatus));
}
}
// If we got this far, something failed, redisplay form
ViewData["PasswordLength"] = MembershipService.MinPasswordLength;
return View(model);
}
//send confirmation code
public void SendConfirmationEmail(string userName)
{
MembershipUser user = Membership.GetUser(userName);
string confirmationGuid = user.ProviderUserKey.ToString();
string verifyUrl = HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority) +
"/account/verify?ID=" + confirmationGuid;
var message = new MailMessage("contacts@abc.com", user.Email)
{
Subject = "Please confirm your email",
Body = verifyUrl
};
var client = new SmtpClient();
client.Send(message);
}
答案 0 :(得分:2)
您想要查看您网站的configuring an Area。
从链接:
为了适应大型项目,ASP.NET MVC允许您对Web进行分区 应用程序分为较小的单元,称为区域。地区 提供一种将大型MVC Web应用程序分离为更小的方法 功能分组。一个区域实际上是一个MVC结构 一个应用程序。应用程序可以包含多个MVC结构 (区域)。
例如,可能会划分单个大型电子商务应用程序 进入代表店面,产品评论,用户的区域 帐户管理和购买系统。每个区域 代表整个应用程序的单独功能。