我正在使用實體框架6.0(代碼優先)在ASP.NET MVC4的登錄/註冊系統,我想知道我應該如何正確處理POST-s。ASP.NET MVC4處理POST模型
我的用戶模型:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
namespace Autokereskedes.Models
{
public class User
{
//Saját Kulcs
[Key]
public int UserId { set; get; }
//Külső kulcsok
//Model hivatkozások
public List<Reservation> Reservations { set; get; }
//Egyedi elemek
[Required]
[EmailAddress]
[StringLength(254)]
[Display(Name = "E-mail")]
public string Email { set; get; }
[Required]
[DataType(DataType.Password)]
[StringLength(100,MinimumLength=4)]
[Display(Name = "Jelszó")]
public string Password { set; get; }
public string Phone { set; get; }
public Boolean Banned { set; get; }
public string Country { set; get; }
public string City { set; get; }
public string Street { set; get; }
public int? ZipCode { set; get; }
public DateTime RegistrationDate { set; get; }
public DateTime? LastLoginDate { set; get; }
public DateTime? PasswordChangedDate { set; get; }
}
}
我的登錄功能:
[HttpPost]
public ActionResult LogIn(User user)
{
if (ModelState.IsValid)
{
if (IsUserDataValid(user.Email, user.Password))
{
FormsAuthentication.SetAuthCookie(user.Email, user.???)
}
}
return View();
}
我要設置永久性的Cookie,基於在登錄表單的複選框,但我的用戶模型沒有有一個public Boolean StayLoggedIn;
屬性,我不希望這個選項也存儲在我的數據庫中。我該如何處理?
我的登錄表單:
@using (Html.BeginForm())
{
@Html.ValidationSummary(true, "Sikertelen belépés, ellenőrizze adataid!");
<div>@Html.LabelFor(u => u.Email)</div>
<div class="input-control text">
@Html.TextBoxFor(u => u.Email, new { @placeholder = "Írja be az email címét"})
@Html.ValidationMessageFor(u => u.Email)
<button class="btn-clear"></button>
</div>
<div>@Html.LabelFor(u => u.Password)</div>
<div class="input-control password">
@Html.TextBoxFor(u => u.Password, new { @placeholder = "Írja be jelszavát" })
@Html.ValidationMessageFor(u => u.Password)
<button class="btn-reveal"></button>
</div>
<label class="input-control checkbox">
<input type="checkbox">
<span class="helper">Bejelentkezve marad</span>
</label>
<input type="submit" value="Bejelentkezés" />
}
我想我會隨之而去。謝謝。 – appl3r