This problem is fixed. Please go to the link below to check how is it being fixed.
[https://github.com/aspnetboilerplate/module-zero/issues/413])
Hope this might help those people who is trying to do prevent multiple login as well. Feel free to ask me if you have any problem and I will try my best to help.
Thanks. /Tommy
<cite>tteoh: </cite> Thanks you ismcagdas, that reply helps us to move on!
The codes below are use to compare the Security Stamps and we are stuck again.
Default data type is string, which is with 2 type parameters:
OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>( validateInterval: TimeSpan.FromMinutes(0), regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
Since that we are using long data type as User PK, so we implemented this, which is with 3 type parameters:
OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<UserManager, User, long>( validateInterval: TimeSpan.FromMinutes(0), regenerateIdentityCallback: (manager, user) => (user.GenerateUserIdentityAsync(manager)), getUserIdCallback: (user) => (long.Parse(user.GetUserId())))
But it's not working. I've tried with ASP.NET MVC project and it's working.
And we saw that most of the ASP.NET MVC examples are with these codes:
app.CreatePerOwinContext(ApplicationDbContext.Create); app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create); app.CreatePerOwinContext<ApplicationSignInManager>(ApplicationSignInManager.Create);
So we are wondering is this the reason why our previous code is not working and do we need to implement this? Or it's implemented by ABP framework already?
Thanks. /Tommy
Dear Support,
Any further guidance on this issue. We suspect CreatePerOwinContext is critical for cookie validation; especially to get an instance of UserManager; otherwise security stamp in cookie and database cannot be compared.
Thanks. /Tommy
Thanks you ismcagdas, that reply helps us to move on!
The codes below are use to compare the Security Stamps and we are stuck again.
Default data type is string, which is with 2 type parameters:
OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
validateInterval: TimeSpan.FromMinutes(0),
regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
Since that we are using long data type as User PK, so we implemented this, which is with 3 type parameters:
OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<UserManager, User, long>(
validateInterval: TimeSpan.FromMinutes(0),
regenerateIdentityCallback: (manager, user) => (user.GenerateUserIdentityAsync(manager)),
getUserIdCallback: (user) => (long.Parse(user.GetUserId())))
But it's not working. I've tried with ASP.NET MVC project and it's working.
And we saw that most of the ASP.NET MVC examples are with these codes:
app.CreatePerOwinContext(ApplicationDbContext.Create);
app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
app.CreatePerOwinContext<ApplicationSignInManager>(ApplicationSignInManager.Create);
So we are wondering is this the reason why our previous code is not working and do we need to implement this? Or it's implemented by ABP framework already?
Thanks. /Tommy
Thank you for the reply, that helped us to have a more understanding about this.
And we found this article that what we wanted: <a class="postlink" href="http://tech.trailmax.info/2015/09/prevent-multiple-logins-in-asp-net-identity/">http://tech.trailmax.info/2015/09/preve ... -identity/</a> We tried to implement this and we're stuck here:
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login"),
Provider = new CookieAuthenticationProvider
{
OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
validateInterval: TimeSpan.FromMinutes(0), // <-- Note the timer is set for zero
regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
}
// other settings
});
We are getting error:
OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
Can you please guide us how to get the 2 objects (ApplicationUserManager & ApplicationUser) from ABP framework?
Another problem is when there are 2 pages open from different browsers, one of the browser is not log out when another browser changed the password
Thanks. /Tommy
I have few problems here due to the findings:
Thanks. /Tommy
<cite>ismcagdas: </cite> Hi @tteoh,
Can you share the code which causes problem for you ? And also the data you have retrieved you don't want to.
Thanks.
Hi, as I mentioned before I'm wondering why the related data is showing even I'm not using Include method
Entity class:
[Table("AppOrganizationChart")]
public class OrganizationChart : Entity<long>
{
public string Name { get; set; }
public long? ParentId { get; set; }
public string Relationship { get; set; }
public int TitleId { get; set; }
[ForeignKey("TitleId")]
public virtual Title Title { get; set; }
}
Code of getting data:
return await _organizationChartRepository
.GetAll()
.ToListAsync();
Output (I get this from swagger):
[
{
"name": "string",
"parentId": 0,
"relationship": "string",
"titleId": 0,
"title": {
"titleName": "string",
"className": "string"
}
}
]
Thanks. /Tommy
I've one problem about the .Include() here.
The data of the relationship is showed even there is not .Include() extension method. May I know why is this happening? Is it because of the relationship that I created on Entity?
[Table("AppOrganizationChart")]
public class OrganizationChart : Entity<long>
{
public string Name { get; set; }
public long? ParentId { get; set; }
public string Relationship { get; set; }
public int TitleId { get; set; }
[ForeignKey("TitleId")]
public virtual Title Title { get; set; }
}
Thanks. /Tommy
<cite>alper: </cite> You can use SeedHelper class
\MyCompanyName.AbpZeroTemplate.EntityFrameworkCore\Migrations\Seed\SeedHelper.cs
I'm using ASP.NET MVC 5.x & Angularjs 1.x, not ASP.NET Core
<cite>alper: </cite> hi
The solution is simple; When you override OnModelCreating you have to run base onmodelcreating method as well. Otherwise you miss the framework migrations.
Basically your code needs to be shaped like this;
protected override void OnModelCreating(DbModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); modelBuilder.Entity<OrganizationChart>() .HasRequired(o => o.User) .WithOptional(u => u.OrganizationChart) .Map(m => m.MapKey("UserId")); }
Can you explain more about this?
Thanks. /Tommy