我正在开发一个 ASP.net Core 2.0 应用程序,它使用 IdentityServer4 令牌服务器进行身份验证。我的应用程序有 Razor Pages,我想使用 Cookie 身份验证,它还有一个 API,我想使用 Bearer 令牌。
\n\n这是我的设置Startup.cs
:
public void ConfigureServices(IServiceCollection services) {\n//...\n services.AddAuthentication(options => { options.DefaultChallengeScheme = "oidc"; })\n .AddIdentityServerAuthentication(JwtBearerDefaults.AuthenticationScheme, options =>\n {\n options.Authority = Configuration["OpenIDConnect:Authority"];\n options.ApiName = Configuration["OpenIDConnect:ApiName"];\n options.JwtBearerEvents.OnChallenge += async context =>\n {\n context.Response.StatusCode = StatusCodes.Status403Forbidden;\n context.HandleResponse();\n };\n })\n .AddCookie(CookieAuthenticationDefaults.AuthenticationScheme)\n .AddOpenIdConnect("oidc", options =>\n {\n options.SignInScheme = "Cookies";\n options.Authority = Configuration["OpenIdConnect:Authority"];\n options.RequireHttpsMetadata = false;\n options.ClientId = Configuration["OpenIdConnect:ClientId"];\n options.SaveTokens = true;\n options.Scope.Add("role");\n options.TokenValidationParameters = new TokenValidationParameters\n {\n NameClaimType …
Run Code Online (Sandbox Code Playgroud) 所以,假设我有一个POCO,我希望EF Code First能够持久存储到数据存储:
public class Campaign
{
public string Name { get; set; }
public double GoalAmount { get; set; }
private double AmountRaised { get; set; }
public bool GoalMet
{
get
{
return AmountRaised >= GoalAmount;
}
}
}
Run Code Online (Sandbox Code Playgroud)
现在,无论出于何种原因,我不希望在AmountRaised
对象外部访问该属性,但我确实希望它持久保存到数据存储中.EF Code First可以实现这一点吗?