2014-03-13 46 views
0

我有MVC.Net C#登錄頁面,我決定做一些奇特的更改,突然我的登錄頁面停止工作。 我需要你的幫助,別人看我的代碼,並可能會看到我無法找到。在調試過程中,它將返回所有true,但不會進入索引頁面。你怎麼看 ?我看不到什麼是我的問題!我的登錄代碼驗證我的憑據,但不要登錄

這裏是我的控制器:

// GET: /Account/Login 

[AllowAnonymous] 
public ActionResult Login(string returnUrl) 
{ 
    ViewBag.ReturnUrl = returnUrl; 
    return View(); 
} 

// 
// POST: /Account/Login 
[HttpPost] 
public ActionResult Login(LoginModel model) 
{ 
    if (ModelState.IsValid) 
    { 
     if (model.IsUserExist(model.EMP_ID, model.EMP_PASSWORD)) 
     { 
      FormsAuthentication.SetAuthCookie(model.EMP_ID, false); 
     } 
     else 
     { 
      ModelState.AddModelError("", "The User ID or Password provided is incorrect."); 
     } 
    } 

    return View(model); 
} 
+2

設置好後authcookie,你都返回相同的登錄視圖。 –

+1

你認爲你在哪裏告訴它去索引視圖? – Chris

回答

2

您將其轉移到任何其他視圖,您可以使用回RedirectToAction("Actionname","controllername","params if any");

// POST: /Account/Login 
    [HttpPost] 
    public ActionResult Login(LoginModel model) 
    { 
     if (ModelState.IsValid) 
     { 
      if (model.IsUserExist(model.EMP_ID, model.EMP_PASSWORD)) 
      { 
       FormsAuthentication.SetAuthCookie(model.EMP_ID, false); 
       //change here 
       return RedirectToAction("Actionname","controllername","params if any"); 

      } 
      else 
      { 
       ModelState.AddModelError("", "The User ID or Password provided is incorrect."); 
      } 
     } 


     return View(model); 
    } 
+0

OMG這是正確的,我怎麼刪除! :(謝謝 – NilR

+1

@NilRad不要擔心它發生在每個人有時:) – Rex

+0

謝謝:)哈哈:) – NilR