How to get session value or cookie value in Telerik reporting

1 Answer 321 Views
.NET Core Report Viewer - HTML5
Dang Dinh
Top achievements
Rank 1
Dang Dinh asked on 04 Aug 2023, 09:51 AM | edited on 04 Aug 2023, 10:20 AM

Dear supporting team,

 

First of all, I apologize for the typo in the title. I can't fix it

I used Telerik reporting to design the report. 

But I was facing a problem. I can not or don't know how to get the session value or cookie value in the ASP.NET Core Web App project.

The way I do it is:

  • Create a new report by Report Designer
  • Create an HTML page, and add the following code

 

    <script type="text/javascript">
        $(document).ready(function () {
            var au = document.cookie.split('=');
            var uname = au[1];

            var urlParams = new URLSearchParams(window.location.search);
            var rp = urlParams.get('r');
            $("#reportViewer1")
            
                .telerik_ReportViewer({
                    
		    serviceUrl: "/api/reports",
                    reportSource: {
                        report: "INV_ADJUSTMENT_DETAIL.trdx",
                        parameters: { user_name: uname, report: rp }
                    },
                    viewMode: telerikReportViewer.ViewModes.INTERACTIVE,
                    scaleMode: telerikReportViewer.ScaleModes.SPECIFIC,
                    scale: 1.0,
                    enableAccessibility: false,
                    sendEmail: { enabled: false },
                    ready: function () {
                    },
                });
        });
    </script>

 

And in the Program.cs

.....
builder.Services.TryAddSingleton<IReportServiceConfiguration>(sp => new ReportServiceConfiguration
{
	ReportingEngineConfiguration = sp.GetService<IConfiguration>(),
	HostAppId = "Html5ReportViewerDemo",
    Storage = new FileStorage(),
	ReportSourceResolver = new CustomReportSourceResolver()
});

builder.Services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
builder.Services.AddHttpContextAccessor();
builder.Services.AddDistributedMemoryCache();
builder.Services.AddSession(session =>
{
	session.IdleTimeout = TimeSpan.FromMinutes(60);
	session.Cookie.HttpOnly = true;
	session.Cookie.IsEssential = true;
});
.....


In the report designer, how can I use the value in reportSource -> parameters?

Is there a possible solution for this? please help advise.

Visual Studio version: Microsoft Visual Studio Professional 2022

Framework: .Net 6.0

Telerik packages:

  • Telerik.Reporting v.17.0.23.315; 
  • Telerik.Reporting.OpenXmlRendering v.17.0.23.315;
  • Telerik.Reporting.Services.AspNetCore 17.0.23.315

    Many thanks,

    Dinh Phong

     


    1 Answer, 1 is accepted

    Sort by
    0
    Dimitar
    Telerik team
    answered on 09 Aug 2023, 08:17 AM

    Hello Dinh,

    Thank you for the attached files and the additional information!

    If I understand correctly, you would like to pass the cookie values to the report file through the reportSource property of the viewer, is that correct?

    In such a case, you need to create corresponding report parameters to which you may pass those values, for example:

    The problem that you have experienced thus far was due to user_name and report parameters not existing in your report so the data wasn't being passed. Once you add those report parameters, you will be able to use their values anywhere in the report.

    For details on how to add and use report parameters, you may have a look at the following articles:

    I hope this will help, please let me know if you have any additional questions.

    Regards,
    Dimitar
    Progress Telerik

    Stay tuned by visiting our roadmap and feedback portal pages, enjoy a smooth take-off with our Getting Started resources, or visit the free self-paced technical training at https://learn.telerik.com/.
    Tags
    .NET Core Report Viewer - HTML5
    Asked by
    Dang Dinh
    Top achievements
    Rank 1
    Answers by
    Dimitar
    Telerik team
    Share this question
    or