C# 找不到资源asp.net mvc

C# 找不到资源asp.net mvc,c#,asp.net,asp.net-mvc,http-post,antiforgerytoken,C#,Asp.net,Asp.net Mvc,Http Post,Antiforgerytoken,我正在熟悉asp.net mvc、Identity并尝试进行简单的注销,但是找不到资源。 在我的html页面中 <li><a href="@Url.Action("LogOff", "Account")" id="home">Log off</a></li> 这在我的路径配置文件中 routes.MapRoute( null, "LogOff", new { controller = "Ac

我正在熟悉asp.net mvc、Identity并尝试进行简单的注销,但是找不到资源。

在我的html页面中

<li><a href="@Url.Action("LogOff", "Account")" id="home">Log off</a></li>
这在我的路径配置文件中

 routes.MapRoute(
         null,
         "LogOff",
         new { controller = "Account", action = "LogOff" }

我可能缺少什么?

注销方法中删除
[HttpPost]

[ValidateAntiForgeryToken]
public ActionResult LogOff()
{
    AuthenticationManager.SignOut();
    return RedirectToAction("Index", "Home");
}

注销方法中删除
[HttpPost]

[ValidateAntiForgeryToken]
public ActionResult LogOff()
{
    AuthenticationManager.SignOut();
    return RedirectToAction("Index", "Home");
}

只需删除HttpPost

public ActionResult LogOff()
{
    AuthenticationManager.SignOut();
    return RedirectToAction("Index", "Home");
}

只需删除HttpPost就可以让我工作

public ActionResult LogOff()
{
    AuthenticationManager.SignOut();
    return RedirectToAction("Index", "Home");
}

适用于我

使用post方法注销。请参见下面的示例

   @using (Html.BeginForm("LogOff", "Account", FormMethod.Post, new { id = "logoutForm" })) {
            @Html.AntiForgeryToken()
            <a href="javascript:document.getElementById('logoutForm').submit()">Log off</a>
        }
@使用(Html.BeginForm(“注销”、“帐户”、FormMethod.Post、新的{id=“logoutForm”})){
@Html.AntiForgeryToken()
}

使用post方法注销。请参见下面的示例

   @using (Html.BeginForm("LogOff", "Account", FormMethod.Post, new { id = "logoutForm" })) {
            @Html.AntiForgeryToken()
            <a href="javascript:document.getElementById('logoutForm').submit()">Log off</a>
        }
@使用(Html.BeginForm(“注销”、“帐户”、FormMethod.Post、新的{id=“logoutForm”})){
@Html.AntiForgeryToken()
}

默认情况下,当您使用某种身份验证创建项目时,它会使用
HttpPost
属性创建
LogOff
方法

所以你有两种方法来修复它

首先删除此属性。让你的代码看起来像

[ValidateAntiForgeryToken]
public ActionResult LogOff()
{
    AuthenticationManager.SignOut();
    return RedirectToAction("Index", "Home");
}
第二个是将html更改为使用带有POST方法的
@html.BeginForm

默认情况下,项目使用第二种实现类型

编辑
当我键入此答案时,请给出一个示例,说明在创建带有某种身份验证的项目时,默认情况下如何使用BeginForm helper,它会创建带有
HttpPost
属性的
LogOff
方法

所以你有两种方法来修复它

首先删除此属性。让你的代码看起来像

[ValidateAntiForgeryToken]
public ActionResult LogOff()
{
    AuthenticationManager.SignOut();
    return RedirectToAction("Index", "Home");
}
第二个是将html更改为使用带有POST方法的
@html.BeginForm

默认情况下,项目使用第二种实现类型

编辑
当我输入这个答案时,Rad给出一个示例如何使用BeginForm helper

Href使用GET方法,但似乎您没有该操作的GET方法Href使用GET方法,但似乎您没有该操作的GET方法现在它也适用于我,tanksNow它也适用于我,tanks