0

以下是我的控制器中的一个登录功能:

[HttpPost]
public ActionResult LogIn(string email, string password)
{          
   return RedirectToAction("Index", "Home");           
}  

这会调用 HomeController 的 Index 函数,但相同的屏幕,即登录屏幕仍保留在浏览器上。以下是我的 MVC 应用程序中的路由:

public static void RegisterRoutes(RouteCollection routes)
{
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                "Default", // Route name
                "{controller}/{action}/{id}", // URL with parameters
                new { controller = "Login", action = "Index", id = UrlParameter.Optional } // Parameter defaults
            );
}  

我不确定是什么问题。我在网上搜索这个,但其他用户面临的问题存在偏差。

更新

家庭控制器:

public class HomeController : Controller
    {
        public ActionResult Index()
        {
            ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application.";

            return View();
        }

        public ActionResult About()
        {
            ViewBag.Message = "Your app description page.";

            return View();
        }

        public ActionResult Contact()
        {
            ViewBag.Message = "Your contact page.";

            return View();
        }
    }
4

1 回答 1

1

Pages such as your Index page on Home Controller will need [AllowAnonymous] decorating the action to allow the page to be viewed without logging in.

do this

public class HomeController : Controller
    {
        [AllowAnonymous]
        public ActionResult Index()
        {
            ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application.";

            return View();
        }

You will also need

[HttpPost]
[AllowAnonymous]
public ActionResult LogIn(string email, string password)
{          
   return RedirectToAction("Index", "Home");           
}  
于 2013-07-18T13:32:08.363 回答