我正在使用带有 OWIN 和 Identity 框架的 Web api 2.2 模板。我故意将我的 DeafultConnection 设置为错误的 IP 地址,但在单步执行并获取不记名 token 和创建声明时没有出现任何错误。
我可以杀死 w3wp.exe,再次启动它,我的 token 仍然有效。那么它在哪里被持久化呢?
我正在我的 GrantResourceOwnerCredentials() 方法中手动验证测试用户
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext() : base("DefaultConnection", throwIfV1Schema: false)
{
}
public static ApplicationDbContext Create()
{
return new ApplicationDbContext();
}
}
最佳答案
I can kill the w3wp.exe, start it up again and my token is still valid. So where is it getting persisted?
OAuth token 根本不持久,在默认的 Owin OAuth2 实现中,它们在设计上是无状态的。每个 token 都包含由服务器加密的为用户发出的声明,以便只有服务器可以解密和验证它。
如果您在不访问数据库的情况下验证您的用户(我假设这就是您在 GrantResourceOwnerCredential
方法中手动所说的意思),那么当然您 DbContext
永远不会被实例化。
关于c# - asp.net 身份表未创建,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36743894/