MVC 4 - 注销控制器行为给予404未找​​到 [英] MVC 4 - LogOff controller action giving 404 not found

查看:171
本文介绍了MVC 4 - 注销控制器行为给予404未找​​到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚结束了一个大学的项目,我不知道如果我一直在看电脑太久,我缺少明显的东西,但是当我尝试了登录用户,我越来越404未找​​到URL /帐号/注销。

I'm just wrapping up a college project, I'm not sure if I've been staring at my computer for too long and am missing something obvious, but when I try to log a user out, I'm getting a 404 not found for the URL /Account/LogOff.

我有一个导航栏,显示登录/注销取决于用户是否,登录,或者登出:

I have a navbar that shows Log in/Log out depending on whether a user is, logged in, or, logged out:

<div class="nav-collapse collapse">
    <ul class="nav pull-right">
        <li class="dropdown" id="dropdown-login-div">
            @if (!Request.IsAuthenticated)
            {
                <a class="dropdown-toggle" href="#" data-toggle="dropdown">Sign In <strong class="caret"></strong></a>
            }
            else
            {
                @Html.ActionLink("Log Off", "LogOff", "Account")
            }
            <div class="dropdown-menu" id="dropdown-login">
                @Html.Partial("~/Views/Account/_LoginPartial.cshtml", new ViewDataDictionary<LetLord.Models.LoginModel>())
            </div>
        </li>
    </ul>
</div>

在我的帐户控制器,自带的模板互联网的默​​认注销等动作:

In my Account controller the default LogOff action that comes with the Internet template:

[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult LogOff()
{
    WebSecurity.Logout();

    return View("Index");
}

有人能告诉我,为什么出现这种情况 - 之前,我把我的笔记本电脑靠在墙上。干杯。

Could someone tell me why this happening - before I throw my laptop against the wall. Cheers.

推荐答案

您使用的链接(&LT; A /&GT; 标签)注销导致< STRONG> HTTP GET 请求时,用户点击了它,但你的行动被限制到只服务(因为它是装饰用上传请求> [HttpPost] 属性)。

You use a link (<a/> tag) to log off which results in HTTP GET request when user clicks on it, but your action is constrained to serve POST request only (because it is decorated with [HttpPost] attribute).

您要么需要把你的链接到表单并产生POST请求,或删除 [HttpPost] [ValidateAntiForgeryToken] 从你的行动(学分GalacticCowboy)。

You either need to put your link into a form and generate POST request, or remove [HttpPost] and [ValidateAntiForgeryToken] (credits to GalacticCowboy) from your action.

这篇关于MVC 4 - 注销控制器行为给予404未找​​到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆