如何重定向到ABP中的登录页面?

How to redirect to login page in ABP?

  1. 我从 ASP.NET 样板网站下载 .NET Core 示例,
  2. 更改数据库连接字符串,更新数据库,
  3. 运行 Web Api,显示Swagger成功,
  4. 添加一个 Home/Index 视图,将 Home/Index 操作更改为 return 视图,而不是 Swagger,
  5. 运行再次显示首页成功,
  6. 然后添加一个 Home.Account 控制器和 Home.Account 查看、登录页面。
  7. 在Home/Index上添加AbpMvcAuthentication属性,我想要的是访问主页时,重定向到登录页面。

当我进入主页时,显示的是一个空白页面,不是主页,也不是登录页面。似乎验证失败,但没有重定向到登录页面。

我的问题是:如何让AbpMvcAuthentication知道在认证失败时重定向到哪个页面?

*.Web.Host project, where the redirect to Swagger 没有登录页面。

您应该将启动项目改为 *。Web.Mvc

如果您只想登录,请考虑从浏览器控制台使用 Swagger authentication helpers

abp.swagger.login();

要回答您的问题,您可以通过还原提交 re-enable 身份验证重定向 92b6270:

// What it was (and what you want)
services.AddAuthentication()
    .AddJwtBearer(options =>

// What it is
services.AddAuthentication(options =>
{
    options.DefaultAuthenticateScheme = "JwtBearer";
    options.DefaultChallengeScheme = "JwtBearer";
}).AddJwtBearer("JwtBearer", options =>

Startup.cs:

app.UseAuthentication();

app.UseJwtTokenMiddleware(); // Add this back

app.UseAbpRequestLocalization();

明确地说,这会重定向到一个空白页面,因为 *.Web.Host 项目没有登录页面.

这与 中的预期行为相反。

此外,您还可以 :

You can configure that in Startup.cs:

IdentityRegistrar.Register(services);
AuthConfigurer.Configure(services, _appConfiguration);

// Add this line:
services.ConfigureApplicationCookie(options => options.LoginPath = "/Admin/Login");

Related docs: https://docs.microsoft.com/en-us/aspnet/core/migration/1x-to-2x/identity-2x