[英]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.