Base solution for your next web application
Open Closed

Custom Session Property in Client #10675


User avatar
0
radhikari1985 created

Prerequisites

Please answer the following questions before submitting an issue. YOU MAY DELETE THE PREREQUISITES SECTION.

  • What is your product version?
    • ASP NET Boilerplate
  • What is your product type (Angular or MVC)?
    • MVC
  • What is product framework type (.net framework or .net core)?
    • .NET CORE

If issue related with ABP Framework

  • 5.14.0

How do I get the custom Property that I added in the Server Side using ClaimsAbpSession, but trying to find out how can we get this in client side like: abp.session.newPropertyName, so it can be access by the client when needed just like other session properties.


3 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    In your {ProjectName}RazorPage.cs class, you can replace AbpSession with your custom session. This is the line it is defined https://github.com/aspnetzero/aspnet-zero-core/blob/dev/aspnet-core/src/MyCompanyName.AbpZeroTemplate.Web.Mvc/Views/AbpZeroTemplateRazorPage.cs#L18.

    After that, you can access it in your razor pages.

  • User Avatar
    0
    radhikari1985 created

    i have already taken these steps and was able to get them in the Server side. however i am not able to get them accessed in the client side abp.session.mynewpropertyName.

    just like abp.session.userId

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @radhikari1985

    You can set a JS variable on the main _Layout.cshtml file liek below;

    window.mynewpropertyName = @"YourSession.MynewpropertyName";
    

    Then, you need to create a new JS file and set it as shown below;

    abp.session.mynewpropertyName = abp.session.mynewpropertyName || window.mynewpropertyName;