I have an ASP.NET Core application running locally where I can access pages using [Authorize]
attribute. However, I can no longer access pages that uses the [Authorize]
propriety when I publish my app to my server. I get the following error: This page can't be found . Other pages without the [Authorize]
attribute are working fine.
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?
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.
If you try to access a controller or action with Authorize attribute, but are not authorized, you should see only a blank page. You can verify this by removing Authorize attribute from the problematic page, and I bet you will still get the same error.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.