要自定义ASP .NET Core Identity的ApiAuthorizationDbContext,您可以按照以下步骤操作:
using Microsoft.AspNetCore.ApiAuthorization.IdentityServer;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Options;
using IdentityServer4.EntityFramework.Options;
public class CustomApiAuthorizationDbContext : ApiAuthorizationDbContext
{
public CustomApiAuthorizationDbContext(
DbContextOptions options,
IOptions operationalStoreOptions) : base(options, operationalStoreOptions)
{
}
}
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
public class Startup
{
private readonly IConfiguration _configuration;
public Startup(IConfiguration configuration)
{
_configuration = configuration;
}
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext(options =>
options.UseSqlServer(_configuration.GetConnectionString("DefaultConnection")));
services.AddDefaultIdentity()
.AddEntityFrameworkStores();
services.AddIdentityServer()
.AddApiAuthorization();
// 其他服务配置
services.AddControllersWithViews();
services.AddRazorPages();
}
// 其他配置方法
}
{
"ConnectionStrings": {
"DefaultConnection": "YourConnectionStringHere"
}
}
通过以上步骤,您将能够自定义ASP .NET Core Identity的ApiAuthorizationDbContext,并在应用程序中使用它。