2014-03-13 45 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