C# AllowAnonymous仅在ASP.NET MVC 5中间歇工作

C# AllowAnonymous仅在ASP.NET MVC 5中间歇工作,c#,asp.net,asp.net-mvc,authentication,owin,C#,Asp.net,Asp.net Mvc,Authentication,Owin,我的一个控制器操作拒绝验证,我无法理解原因。这只是visual studio中标准MVC 5项目模板中的标准VerifyCode操作,如下所示: [AllowAnonymous] public async Task<ActionResult> VerifyCode(string provider, string returnUrl, bool rememberMe) { if (!await SignInManager.HasBeenVerifiedAsync())

我的一个控制器操作拒绝验证,我无法理解原因。这只是visual studio中标准MVC 5项目模板中的标准VerifyCode操作,如下所示:

[AllowAnonymous]
public async Task<ActionResult> VerifyCode(string provider, string returnUrl, bool rememberMe)
{
    if (!await SignInManager.HasBeenVerifiedAsync())
    {
        return View("Error");
    }
    return View(new VerifyCodeViewModel { Provider = provider, ReturnUrl = returnUrl, RememberMe = rememberMe });
}
如果在没有登录用户的情况下直接命中,则可以正常工作

因此,为了尝试了解发生了什么,我在控制器中添加了以下测试操作:

// to see if it's down to the parameters
[AllowAnonymous]
public ActionResult VerifyCode()
{
    return View(new VerifyCodeViewModel { Provider = "", ReturnUrl = "", RememberMe = false });
}

// to see if it's down to the action name
[AllowAnonymous]
public ActionResult VerifyCod()
{
    return View(new VerifyCodeViewModel { Provider = "", ReturnUrl = "", RememberMe = false });
}

// to see if it's down to the viewmodel
[AllowAnonymous]
public ActionResult ForgotPassword()
{
    return View(new VerifyCodeViewModel { Provider = "", ReturnUrl = "", RememberMe = false });
}
点击前两个会导致我的应用程序将我发送回登录页面。点击第三个按钮,则会无问题地呈现放弃的密码视图


我没有任何自定义授权筛选器。这里到底发生了什么?

检查您的.vs/config/applicationhost.config文件,并验证以下部分是否设置为拒绝和true

<section name="anonymousAuthentication" overrideModeDefault="Deny" />
<add name="AnonymousAuthenticationModule" lockItem="true" />

检查您的.vs/config/applicationhost.config文件,并验证以下部分是否设置为Deny和true

<section name="anonymousAuthentication" overrideModeDefault="Deny" />
<add name="AnonymousAuthenticationModule" lockItem="true" />


找到了它们。它们的设置如所述。您在控制器本身上设置了什么标志?找到了。它们的设置如所述。您在控制器本身上设置了哪些标志?