繁体   English   中英

ASP.NET Core-发布应用程序时找不到具有[Authorize]属性的页面

[英]ASP.NET Core - Pages with `[Authorize]` attribute cannot be found when app is published

我有一个本地运行的ASP.NET Core应用程序,可以使用[Authorize]属性访问页面。 但是,当我将应用发布到服务器时,我将无法再访问使用[Authorize]属性的页面。 我收到以下错误: 找不到此页面 没有[Authorize]属性的其他页面运行正常。

编辑:我发现我的应用程序在发布版本上出现错误。 我猜我的SignInManager在发布时无法正常工作。如何配置?

这是我的服务代码。

public class IdentityAuthenticationService : IAuthenticationService
{
    private UserManager<IdentityApplicationUser> userManager;
    private SignInManager<IdentityApplicationUser> signInManager;
    private RoleManager<IdentityRole> roleManager;

    public IdentityAuthenticationService
    (
        UserManager<IdentityApplicationUser> userManager, 
        SignInManager<IdentityApplicationUser> signInManager,
        RoleManager<IdentityRole> roleManager
    )
    {
        this.userManager = userManager;
        this.signInManager = signInManager;
        this.roleManager = roleManager;
    }

    public async Task LoginAsync(string username, string password)
    {
        //This line is where the error comes from
        var result = await signInManager.PasswordSignInAsync(username, password, isPersistent: false, lockoutOnFailure: false);
        if (!result.Succeeded) {
            throw new InvalidLoginException();
        }
    }
    [...]

我认为您的问题不在于Authorize属性,而更可能是路由。

如果您尝试访问具有Authorize属性的控制器或操作,但未获得授权,则应该只会看到一个空白页。 您可以通过从有问题的页面中删除“授权”属性来验证这一点,我敢打赌,您仍然会遇到相同的错误。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM