簡體   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