我有以下mvc应用程序
问题是当我尝试分配配置文件值时:
// Attempt to register the user
MembershipCreateStatus createStatus = MembershipService.CreateUser(model.Email, model.Password);
if (createStatus == MembershipCreateStatus.Success)
{
//Adding role
MembershipService.AddDefaultRole(model.Email);
FormsService.SignIn(model.Email, false /* createPersistentCookie */);
//Add other initial profile data
HttpContext.Profile["FirstName"] = model.FirstName; //PROBLEM
HttpContext.Profile["LastName"] = model.LastName; //PROBLEM
return RedirectToAction("List", new { area = "", controller = "Requests" });
}
else
{
ModelState.AddModelError("", AccountValidation.ErrorCodeToString(createStatus));
}
Inside FormsService.SignIn(model.Email,false):
public void SignIn(string email, bool createPersistentCookie)
{
if (String.IsNullOrEmpty(email)) throw new ArgumentException("Value cannot be null or empty.", "email");
FormsAuthentication.SetAuthCookie(email, createPersistentCookie);
}
为什么在调用FormsAuthentication.SetAuthCookie后,用户尚未通过身份验证? 我收到错误b.c.我试图为匿名用户分配一些个人资料值。
有什么想法吗?
答案 0 :(得分:1)
当你设置一个cookie时,它被添加到Response中,但IsAuthenticated bool是从Request中设置的。设置身份验证并设置会话变量后,您应该重定向到另一个页面,如主页或原始请求。