简体   繁体   English

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

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

I have an ASP.NET Core application running locally where I can access pages using [Authorize] attribute. 我有一个本地运行的ASP.NET Core应用程序,可以使用[Authorize]属性访问页面。 However, I can no longer access pages that uses the [Authorize] propriety when I publish my app to my server. 但是,当我将应用发布到服务器时,我将无法再访问使用[Authorize]属性的页面。 I get the following error: This page can't be found . 我收到以下错误: 找不到此页面 Other pages without the [Authorize] attribute are working fine. 没有[Authorize]属性的其他页面运行正常。

EDIT : I found where my application is getting an error on my publish version. 编辑:我发现我的应用程序在发布版本上出现错误。 I'm guessing my SignInManager isn't working correctly when I'm published.. how could I configure it? 我猜我的SignInManager在发布时无法正常工作。如何配置?

Here's the code of my service. 这是我的服务代码。

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();
        }
    }
    [...]

I don't think your problem is with Authorize attribute, but more likely routing. 我认为您的问题不在于Authorize属性,而更可能是路由。

If you try to access a controller or action with Authorize attribute, but are not authorized, you should see only a blank page. 如果您尝试访问具有Authorize属性的控制器或操作,但未获得授权,则应该只会看到一个空白页。 You can verify this by removing Authorize attribute from the problematic page, and I bet you will still get the same error. 您可以通过从有问题的页面中删除“授权”属性来验证这一点,我敢打赌,您仍然会遇到相同的错误。

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

相关问题 ASP.NET Core 2授权属性jwt - ASP.NET Core 2 Authorize attribute jwt ASP.NET Core自定义授权属性 - ASP.NET Core Custom Authorize Attribute ASP.NET Core-发布应用程序后无法使用signInManager登录 - ASP.NET Core - Unable to signIn with signInManager when app is published 在 asp.net 核心中使用身份时未找到具有授权属性的操作 - Not Found for actions with Authorize attribute while using identity in asp.net core 在ASP.NET Core授权属性中将存储库与DbContext一起使用:“无法访问已处置的对象” - Use repository with DbContext in ASP.NET Core Authorize-Attribute: “Cannot access a disposed object” ASP.Net Core 2.1/WebAPI 应用程序:“未找到 HTTP 404”使用 [授权] 调用 REST url - ASP.Net Core 2.1/WebAPI app: "HTTP 404 not found" calling a REST url with [Authorize] ASP.NET Core 授权属性不适用于 JWT - ASP.NET Core Authorize attribute not working with JWT 在ASP.NET Core中使用授权属性和自定义Cookie身份验证 - Using the Authorize Attribute with Custom Cookie Authentication in ASP.NET Core 违反ASP.NET Core中的Authorize属性的默认行为是什么 - What is the default behavior of violating the Authorize attribute in ASP.NET Core Asp.Net Core WebApi:授权属性错误403 - Asp.Net Core WebApi: Authorize attribute Error 403
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM