本文整理汇总了C#中IAuthenticator.SetCookie方法的典型用法代码示例。如果您正苦于以下问题:C# IAuthenticator.SetCookie方法的具体用法?C# IAuthenticator.SetCookie怎么用?C# IAuthenticator.SetCookie使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IAuthenticator
的用法示例。
在下文中一共展示了IAuthenticator.SetCookie方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Create
public ActionResult Create(UserInputModel userInputModel)
{
_repository = new InMemoryRepository();
_authenticator = new CookieAuthenticator();
if (_repository.GetAll<User>().Any(x => x.Username == userInputModel.Username))
{
ModelState.AddModelError("Username", "Username is already in use");
}
if (ModelState.IsValid)
{
var user = new User
{
Id = Guid.NewGuid(),
Username = userInputModel.Username,
Password = HashPassword(userInputModel.Password),
};
_repository.SaveOrUpdate(user);
_authenticator.SetCookie("72201781859E67D4F633C34381EFE4BC928656AEE324A4B00CADA968ACD6CF33047E47479B0B68050FF4A0DB13688B5C78DAFDF53252A94E7F1D7B58A6FFD95D747F3D3AA761DECA7B6358A2E78B85D868833A9420316BDA8A5A0425D543AC1148CB69B902195C20065446A5E5F7A8E4C94A04A22304680E1211F00A12DF5E8777A343D08D0F8C0A3BFC471381E9B070E0F0608ADAEBCA8E233A21251BF57A03B52C1F03B7169CFC7C98216E7217EA649C4EDBD35E07F11A2444D40BE303BFFA28BAA921CDCC298D09A6E0297ED7D6E8");
return RedirectToAction("Index", "Home");
}
return View("New", userInputModel);
}
示例2: Create
public ActionResult Create(SessionViewModel sessionViewModel)
{
User user = null;
_repository = new InMemoryRepository();
_authenticator = new CookieAuthenticator();
if (ModelState.IsValid)
{
user = _repository.GetAll<User>().SingleOrDefault(x => x.Username == sessionViewModel.Username);
if (user == null)
{
ModelState.AddModelError(string.Empty, errorMessage);
}
}
if (ModelState.IsValid)
{
if (!BCrypt.Net.BCrypt.Verify(sessionViewModel.Password, user.Password))
{
ModelState.AddModelError(string.Empty, errorMessage);
}
}
if (ModelState.IsValid)
{
_authenticator.SetCookie(user.Username);
var returnUrl = sessionViewModel.ReturnUrl;
if (returnUrl != null)
{
Uri returnUri;
if (Uri.TryCreate(returnUrl, UriKind.Relative, out returnUri))
{
return Redirect(sessionViewModel.ReturnUrl);
}
}
return RedirectToAction("Index", "Home");
}
return View("New", sessionViewModel);
}