Base solution for your next web application
Ends in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

How to set new session value #6719


User avatar
0
kalidarscope created

I would like to add new session value after i login into application. I have got the following error.

System.NullReferenceException: Object reference not set to an instance of an object.
   at ASAP.ASAPEnvHub.ASAPEnvHubAppService.sessionenvidAsync(String value) in D:\PROJECT\ASAP_11022019\src\ASAP.Application\ASAPEnvHub\ASAPEnvHubAppService.cs:line 286
   at lambda_method(Closure , Object )
   at Microsoft.AspNetCore.Mvc.Internal.ActionMethodExecutor.AwaitableObjectResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeActionMethodAsync()
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeNextActionFilterAsync()

The code what i have tried to add the value in session.

 public async Task<GetASAPEnvHubForEditOutput> sessionenvidAsync(string value)
        {
           
              
                string val = ASAPSessions.Envid;
                var user = await _userManager.FindByIdAsync(AbpSession.UserId.ToString());
                var claim = await _principalFactory.CreateAsync(user);              
                if (string.IsNullOrEmpty(user.OrganizationId) == false)
                {
                    claim.Identities.First().AddClaim(new Claim("Envid", value));
                    SingleTon.Instance.AddValues("Envid", value);
                }
                var envHub = await _envHubRepository.FirstOrDefaultAsync(s => s.ENV_ID == value);
                return ObjectMapper.Map<GetASAPEnvHubForEditOutput>(envHub);
        
           
           
        }

Could you please assit me to solve this.


1 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team

    https://support.aspnetzero.com/QA/Questions/6721 Are these two questions one?