jsreport / jsreport-dotnet

jsreport .NET sdk home repository
https://jsreport.net
MIT License
63 stars 10 forks source link

LocalReporting Jsreport azure Web App #28

Closed vidya091209 closed 2 years ago

vidya091209 commented 5 years ago

I am hosting a .net core app in azure web app. services.AddJsReport(new LocalReporting().UseBinary(JsReportBinary.GetBinary()).AsUtility().Create()); HttpContext.JsReportFeature().Recipe(Recipe.ChromePdf,) .OnAfterRender((r) => HttpContext.Response.Headers["Content-Disposition"] =filename); i want to download the report. locally it works but from web app it just render as html report.

pofider commented 5 years ago

Please share the full code of the controller method.

vidya091209 commented 5 years ago

[MiddlewareFilter(typeof(JsReportPipeline))] public async Task Download(string id, string status, string type="PDF") { ViewBag.Status = status;

        var filename=$"attachment; filename=\"Customer List_{DateTime.Now.ToString("MM-dd-yy-HH-MM-ss") }.pdf\"";
        HttpContext.JsReportFeature().Recipe(Recipe.ChromePdf)
            .OnAfterRender((r) => HttpContext.Response.Headers["Content-Disposition"] =filename);
        return View("Customer", await _customerService.GetCustomerSearchAsync(new ViewModel.CustomerFilter() { CustomerTypeId=id }));
    }
pofider commented 5 years ago

Hm, this looks good. I don't see any reason why it should return something different in azure web app. Do you get this problem just in this particular case or is it general?

vidya091209 commented 5 years ago

is there any limitation in using azure web app. i have seen there was a issue reported for the same.

pofider commented 5 years ago

See it in the docs https://jsreport.net/learn/dotnet-local#azure-web-apps

vidya091209 commented 5 years ago

this means at minimum i have to have linux container running

pofider commented 5 years ago

Yes. However the chrome should just fail on windows. It is strange that it is returning html for you.

vidya091209 commented 5 years ago

Hi I have modified my docker file as

FROM microsoft/dotnet:2.2-aspnetcore-runtime AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
RUN apt-get update && \   
    apt-get install -y gnupg  libgconf-2-4 wget && \
    wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - && \
    sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' && \
    apt-get update && \
    apt-get install -y google-chrome-unstable --no-install-recommends

ENV chrome:launchOptions:args --no-sandbox

The main issue i am facing is adding nuget package it is taking more than 3 hours to download but even after that it is getting timeout.

vidya091209 commented 5 years ago

nuget package Include="jsreport.Binary.Linux"

pofider commented 5 years ago

I prepared an example for docker and azure web app. Can you check it? How it works for you?

https://github.com/jsreport/jsreport-dotnet-example-docker

vidya091209 commented 5 years ago

thanks. it is working. but performance wise it is too slow. for 57KB report it is taking more than 1 minute.

pofider commented 5 years ago

The rendering should be slow just the first time. Isn't it?

You can try to use this "AsWebServer" switch https://jsreport.net/learn/dotnet-local#utility-or-web-server which can speed it up a bit.

What azure plan do you use? How is the performance on your local?

vidya091209 commented 5 years ago

Its Standard S1. locally it is a faster.

vidya091209 commented 5 years ago

but you recommend to use "It is generally recommended to use the utility based strategy in production"

vidya091209 commented 5 years ago

Hi @pofider one the same instance i also wanted to support to download excel. this my local running code but in docker it is showing as inline

HttpContext.JsReportFeature() // the normal jsreport base url injection into the html doesn't work properly with docker and asp.net because of port mapping // the project typically starts with some http://localhost:1234 url but inside docker the url is http://localhost .Configure((req) => { req.Options.Base = "http://localhost"; req.Template.HtmlToXlsx = new HtmlToXlsx() { HtmlEngine = "chrome" }; }) .Recipe(Recipe.HtmlToXlsx);

pofider commented 5 years ago

one the same instance i also wanted to support to download excel. this my local running code but in docker it is showing as inline

you mean it shows in excel online? I tried the same code in the previously shared example and excel gets downloaded if I run the controller action in a browser. However, you can change the AfterRender hook to change the content disposition header.

thanks. it is working. but performance wise it is too slow. for 57KB report it is taking more than 1 minute

I tried the previously shared example with demo invoice on S1 plan and it runs 4s. You can also deploy jsreport as standalone web app from docker image "jsreport/jsreport:2.3.0" to get it separated with better architecture and better performance. You would get like 2.5s there on S1. Unfortunatelly S1 is quite slow for running a heavy tool like headless chrome.

vidya091209 commented 5 years ago

No excel report is rendering as html. please update the sample code https://github.com/jsreport/jsreport-dotnet-example-docker to support excel download. thanks.

pofider commented 5 years ago

You can also consider using [jsreportonline(https://jsreport.net/online) instead of the jsreport.Local. It is in many situations more effective for maintenance and resources cost. Just giving you options...

pofider commented 5 years ago

I added the excel example, but there is nothing interesting. Check it out.

vidya091209 commented 5 years ago
capture

this is how my report is looking right now instead of getting downloaded.

and we don't need this right? .OnAfterRender((r) => HttpContext.Response.Headers["Content-Disposition"] = filename);

pofider commented 5 years ago

and we don't need this right?

No it should not be needed.

It must be something with your setup, I don't know. Try to compare it with my example and find out what is different. Or share a simple sample repo for me so I can take a look.

pofider commented 2 years ago

A lot has changed in the jsreport v3 sdk, please test it there and come back if you have still troubles.