【发布时间】:2015-09-17 07:43:01
【问题描述】:
我正在使用 Intranet,到目前为止,我已从 Windows 身份验证切换到 表单身份验证,并且可以连接/注册等。
但这是我应该做的:我希望链接员工列表(具有许多参数),而不是通过通常的表单路径创建和帐户,例如登录名、密码、姓名等),并且能够在我创建新员工时创建新用户。
这是我的员工创建控制器:
public ActionResult Create()
{
ViewBag.CompanyList = _service.ListCompany();
ViewBag.SupervisorList = _service.ListSupervisor();
return View();
}
//
// POST: /Employee/Create
[HttpPost]
public ActionResult Create([Bind(Exclude = "Id")] Employee objEmployee, FormCollection form)
{
ViewBag.CompanyList = _service.ListCompany();
ViewBag.SupervisorList = _service.ListSupervisor();
objEmployee.CreatedDate = System.DateTime.Now;
objEmployee.UpdatedDate = System.DateTime.Now;
objEmployee.CompanyId = int.Parse(form["CompanyId"]);
objEmployee.Supervisor = form["Supervisor"];
if (_service.Create(objEmployee))
return new RedirectResult(Url.Action("Index"));
else
{
if (!_service.Validate(objEmployee))
return View();
else
return new RedirectResult(Url.Action("Index", "Error", new { Message = "Error Create Employee", NextPage = CRAWebSiteMVC.Properties.Resources.Employee + @"/" + CRAWebSiteMVC.Properties.Resources.Create }));
}
}
这是我通过普通表单身份验证创建帐户的通常方式。注册:
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public ActionResult Register(RegisterModel model)
{
if (ModelState.IsValid)
{
// Attempt to register the user
try
{
WebSecurity.CreateUserAndAccount(model.UserName, model.Password);
WebSecurity.Login(model.UserName, model.Password);
return RedirectToAction("Index", "Home");
}
[...]
}
// If we got this far, something failed, redisplay form
return View(model);
}
我怎样才能通过员工创建面板创建一个帐户,并基本上用员工列表替换通常的用户列表?
【问题讨论】:
-
您的意思是同时创建一个电子邮件模型。将其添加到 UserStore 和 UserManager 类中?我希望您知道您可以使用 UserStore 和 UserManager 类来创建您所说的“普通用户”。
-
作为新技术的新手,我没有。我会调查的。
标签: c# asp.net-mvc sql-server-2008 forms-authentication