1

我希望 Logout 链接执行位于HomeController而不是显示新的View. 我该如何构建这个?

控制器方法:

public ActionResult LogoutProcess()
    {
        previousLoggedIn = WebSecurity.CurrentUserName;
        WebSecurity.Logout();
        return RedirectToAction("Logout", "Home");
    }

    public ActionResult Logout(HomeModels.LogoutModel model)
    {
        model.PreviouslyLoggedInUsername = previousLoggedIn;
        return View(model);
    }

看法:

<a href = "@Url.Action("LogoutProcess", "Home")">Logout</a>
4

3 回答 3

1

您可以使用标准链接,针对该操作

@Url.Action("LogoutProcess", "Home")

“技巧”是在您的操作结束时重定向到其他视图LogoutProcess()

public ActionResult LogoutProcess()
{
    // TempData to transfer user name      
    TempData["previousLoggedIn"] = WebSecurity.CurrentUserName;
    WebSecurity.Logout();
    return RedirectToAction("Logout", "Home");
}

public ActionResult Logout(HomeModels.LogoutModel model)
{
    // fill model from TempData
    model.PreviouslyLoggedInUsername = TempData["previousLoggedIn"];
    return View(model);
}

通过CurrentUserName传递给其他动作TempData

于 2013-01-14T10:06:03.773 回答
0

试试这个:

public ActionResult LogoutProcess()
{
    WebSecurity.Logout();
    //return null;
    Return RedirectToAction("Index");//or whatever page you want to display after logout.
}
于 2013-01-14T10:06:17.610 回答
0

您是否考虑过无内容 http 状态码结果?

return new HttpStatusCodeResult(HttpStatusCode.NoContent);
于 2013-01-14T10:13:16.890 回答