Hi Zony,
I can't hear anything from you. Please....
Hi wizgod,
This ticket solved my problems . https://support.aspnetzero.com/QA/Questions/9972/Error-when-removing-table-prefix-in-v101. 1.Delete all migration files in the Migrations folder. 2.Regenerate a new migration. 3.Run the Migrator program.
I have alread sent the files to your [email protected]. Please check it.
Hi Zony, Thanks for your reply. I did your follow. But it's still null value. Not show "Hello World". Look my code.
In Application layer public class NameNgCoreApplicationModule : AbpModule { public override void PreInitialize() { //Adding authorization providers Configuration.Authorization.Providers.Add<AppAuthorizationProvider>();
//Adding custom AutoMapper configuration
Configuration.Modules.AbpAutoMapper().Configurators.Add(CustomDtoMapper.CreateMappings);
//For CustomClaimFactory
IocManager.IocContainer.Register(
Component
.For<IUserClaimsPrincipalFactory<User>, CustomClaimFactory>()
.LifestyleTransient()
.IsDefault());
}
public override void Initialize()
{
IocManager.RegisterAssemblyByConvention(typeof(BEZNgCoreApplicationModule).GetAssembly());
}
}
I created "CustomClaimFactory" class in NameNgCore.Core project.
public class CustomClaimFactory : AbpUserClaimsPrincipalFactory<User, Role> { private readonly IRepository<Guest, Guid> _guestRepository; private readonly IRepository<Reservation, Guid> _reservationRepository; private readonly IRepository<Room, Guid> _roomRepository;
public CustomClaimFactory(AbpUserManager<Role, User> userManager,
AbpRoleManager<Role, User> roleManager,
IOptions<IdentityOptions> optionsAccessor,
IRepository<Guest, Guid> guestRepository,
IRepository<Reservation, Guid> reservationRepository,
IRepository<Room, Guid> roomRepository
) : base(userManager,
roleManager,
optionsAccessor)
{
_guestRepository = guestRepository;
_reservationRepository = reservationRepository;
_roomRepository = roomRepository;
}
public override async Task<ClaimsPrincipal> CreateAsync(User user)
{
var claim = await base.CreateAsync(user);
var resObj = (from res in _reservationRepository.GetAll()
join gs in _guestRepository.GetAll() on res.GuestKey equals gs.Id
join r in _roomRepository.GetAll() on res.RoomKey equals r.Id
where (res.Status == 1 || res.Status == 2) && (gs.EMail == user.EmailAddress || gs.LastName == user.UserName)
select new
{
DocNo = res.DocNo,
ReservationKey = res.Id,
GuestKey = gs.Id
}).FirstOrDefault();
// resObj has value
if (resObj != null)
{
claim.Identities.First().AddClaim(new Claim("Application_DOCNO", "Hello World"));
}
return claim;
}
}
public interface IMyAppSession
{
string DOCNO { get; }
}
public class MyAppSession : ClaimsAbpSession, ITransientDependency,IMyAppSession
{
public MyAppSession(
IPrincipalAccessor principalAccessor,
IMultiTenancyConfig multiTenancy,
ITenantResolver tenantResolver,
IAmbientScopeProvider<SessionOverride> sessionOverrideScopeProvider) :
base(principalAccessor, multiTenancy, tenantResolver, sessionOverrideScopeProvider)
{
}
public string DOCNO
{
get
{
var userDocClaim = PrincipalAccessor.Principal?.Claims.FirstOrDefault(c => c.Type == "Application_DOCNO");
if (userDocClaim == null || string.IsNullOrEmpty(userDocClaim?.Value))
{
return null;
}
return userDocClaim.Value;
}
}
}
This is TokenAuthController in NameNgCore.Web.Core project
which call store values
public class TokenAuthController : NameNgCoreControllerBase
{
private readonly IUserClaimsPrincipalFactory<User> _iclaimsPrincipalFactory;
private readonly IMyAppSession _p;
public TokenAuthController(IMyAppSession p,
IUserClaimsPrincipalFactory<User> iclaimsPrincipalFactory
)
{
_p = p;
_iclaimsPrincipalFactory = iclaimsPrincipalFactory;
}
[HttpPost]
public async Task<AuthenticateResultModel> Authenticate([FromBody] AuthenticateModel model)
{
your code ...ok....then.......
var loginResult = await GetLoginResultAsync(
model.UserNameOrEmailAddress,
model.Password,
GetTenancyNameOrNull()
);
..........
var refreshToken = CreateRefreshToken(await CreateJwtClaims(loginResult.Identity, loginResult.User,
tokenType: TokenType.RefreshToken));
var accessToken = CreateAccessToken(await CreateJwtClaims(loginResult.Identity, loginResult.User,
refreshTokenKey: refreshToken.key));
var claims = await _iclaimsPrincipalFactory.CreateAsync(loginResult.User);
var d =_p.DOCNO ; // here value is null. Actually it must show "Hello World"
return new AuthenticateResultModel
{
AccessToken = accessToken,
ExpireInSeconds = (int)_configuration.AccessTokenExpiration.TotalSeconds,
RefreshToken = refreshToken.token,
RefreshTokenExpireInSeconds = (int)_configuration.RefreshTokenExpiration.TotalSeconds,
EncryptedAccessToken = GetEncryptedAccessToken(accessToken),
TwoFactorRememberClientToken = twoFactorRememberClientToken,
UserId = loginResult.User.Id,
ReturnUrl = returnUrl
};
}
}
please help me..Is there anything path?
I need some data to store in session which is reuse after logined. I had override CreateAsync(User user) method in UserClaimsPrincipalFactory.cs. Look it
public override async Task CreateAsync(User user)
{
var claim = await base.CreateAsync(user);
var resObj = (from res in _reservationRepository.GetAll()
join gs in _guestRepository.GetAll() on res.GuestKey equals gs.Id
join r in _roomRepository.GetAll() on res.RoomKey equals r.Id
where (res.Status == 1 || res.Status == 2) && (gs.EMail == user.EmailAddress || gs.LastName == user.UserName)
select new
{
DocNo = res.DocNo,
ReservationKey = res.Id,
GuestKey = gs.Id
}).FirstOrDefault();
if (resObj != null)
{
claim.Identities.First().AddClaim(new Claim("Application_DOCNO", resObj.DocNo));
}
return claim;// it is ok. Docno value have in claims.
}
Then I created MyAppSession Class folowing :
public class MyAppSession : ClaimsAbpSession, ITransientDependency,IMyAppSession
{
public MyAppSession(
IPrincipalAccessor principalAccessor,
IMultiTenancyConfig multiTenancy,
ITenantResolver tenantResolver,
IAmbientScopeProvider<SessionOverride> sessionOverrideScopeProvider) :
base(principalAccessor, multiTenancy, tenantResolver, sessionOverrideScopeProvider)
{
}
public string DOCNO
{
get
{
var userDocClaim = PrincipalAccessor.Principal?.Claims.FirstOrDefault(c => c.Type == "Application_DOCNO");
if (userDocClaim == null || string.IsNullOrEmpty(userDocClaim?.Value))
{
return null;
}
return userDocClaim.Value;
}
}
This is IMyAppSession Interface
public interface IMyAppSession
{
string DOCNO { get; }
}
This is session value retrive class
public class TokenAuthController : BEZNgCoreControllerBase
{
private readonly IMyAppSession \_p;
public TokenAuthController(IMyAppSession p)
{
\_p = p;
}
public string GetSession()
{
return _p.DOCNO;// Here value is null. Why?
}
}
Is there anything need to change? Please help me.
What is your product version? 10.1 What is your product type (Angular or MVC)? Angular What is product framework type (.net framework or .net core)? .net 5
After I downloaded latest version 10.1 and run Update-Database to create database, db is successfully created. Then I added modelBuilder.ChangeAbpTablePrefix<Tenant, Role, User>("") to remove abp prefix. I run Add-Migration "Remove_ABP_Prefix" first then run Update-Database. I got this screen shot errors. Do I need to change anything?
Hi ismcagdas ,
When will release 10.1 and this removing table prefix fix in 10.1 version?
Thanks
Hi ismcagdas,
Any suggestions for this problems ? We still cannot solve yet.
Thanks