C# C Visual Studio发布表单将转到不同的路径

C# C Visual Studio发布表单将转到不同的路径,c#,forms,http-post,C#,Forms,Http Post,我在RetrievePassword.cshtml中有此表单: 但是,当我单击表单中的“提交”按钮时,网页尝试导航到/Accounts/Login,URL为localhost:58893/Account/Login?ReturnUrl=%fUsers%2SendPassword。帐户控制器存在,但没有登录方法。但是,如果在Users控制器中删除SendPassword方法,我会得到正确的Users/SendPassword URL,但当然不会显示任何内容,因为没有附加任何方法或视图 你知道为什么

我在RetrievePassword.cshtml中有此表单:

但是,当我单击表单中的“提交”按钮时,网页尝试导航到/Accounts/Login,URL为localhost:58893/Account/Login?ReturnUrl=%fUsers%2SendPassword。帐户控制器存在,但没有登录方法。但是,如果在Users控制器中删除SendPassword方法,我会得到正确的Users/SendPassword URL,但当然不会显示任何内容,因为没有附加任何方法或视图


你知道为什么它试图导航到Account/Login而不是Users/SendPassword吗?或者为什么只有在我删除控制器中的方法时URL才正确?

您的SendPassword操作没有像上面那样包含[AllowAnonymous]属性

由于您当前的设置,ASP.NET正试图通过将您发送到帐户/登录路径对您进行身份验证

如果您需要能够在不经过身份验证的情况下发布SendPassword操作,请向其添加[AllowAnonymous]属性,如下所示:

[AllowAnonymous, HttpPost]
public ActionResult SendPassword(string email)
[AllowAnonymous]
public ActionResult RetrievePassword() 
{
    return View();
}

[HttpPost]
public ActionResult SendPassword(string email)
{
    System.Diagnostics.Debug.WriteLine("SendPassword POST");
    return null;
}
[AllowAnonymous, HttpPost]
public ActionResult SendPassword(string email)