-2
這是登錄, 這是用戶登錄控制器代碼,我驗證用戶的電子郵件ID和密碼,當用戶登錄重定向到首頁的控制器代碼控制器在這裏我想顯示用戶信息我做一個登錄頁面,我想顯示用戶信息名址等,當我登錄成功
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Login(UserLogin login, string ReturnUrl = ""){
string message = "";
using (LoginEntities dc = new LoginEntities()){
var v = dc.Users.Where(a => a.EmailID == login.EmailID).FirstOrDefault();
var n = dc.Users.Where(a => a.Password == login.Password).FirstOrDefault();
if (v != null || n != null){
if (string.Compare(Crypto.Hash(login.Password), v.Password) == 0){
int timeout = login.RememberME ? 525600 : 20;
var ticket = new FormsAuthenticationTicket(login.EmailID,login.RememberME,timeout);
string encrypted = FormsAuthentication.Encrypt(ticket);
var cookie = new HttpCookie(FormsAuthentication.FormsCookieName, encrypted);
cookie.Expires = DateTime.Now.AddMinutes(timeout);
cookie.HttpOnly = true;
Response.Cookies.Add(cookie);
if (Url.IsLocalUrl(ReturnUrl)){
return Redirect(ReturnUrl);
}
else{
return RedirectToAction("Index", "Home");
}
}
else{
message = "Invalid Credential Provided";
}
}
else {
message = "Invalid Credential Provided";
}
}
ViewBag.Message = message;
return View();
}
家庭控制器和索引操作,我重定向當我登錄, 這是家庭控制器哪裏重定向成功登錄後,請了一些人給家居控制器和索引操作代碼在哪裏我可以獲取用戶的ID登錄和,並告訴我如何顯示在視圖
public class HomeController : Controller{
LoginEntities db = new LoginEntities();
// GET: Home
[Authorize]
public ActionResult Index(){
if (Session.Contents.Count == 0){
RedirectToAction("Login", "User");
}
return View();
}
}
當我登錄按鈕單擊登錄可以看到他的名字姓氏日期等是在用戶模型persent用戶費爾南Vacina我只需要.. 。我必須編寫代碼以及如何傳遞它以查看 – Shahab
Hi @Shahab添加了上面的示例,希望有所幫助(請注意,如果它實際上可行,但沒有經過測試,但邏輯應該在代碼中應該如何調用) –