c# - 如何设置 JsReport .NET 以使用当前应用程序文件夹

标签 c# .net asp.net-mvc temp jsreport

有没有办法设置 JsReport 使用当前应用程序文件夹来存储临时文件。不使用公共(public)文件夹 C:\Windows\Temp\jsreport?如果在普通 IIS 上运行多个应用程序,则会产生错误。

Error rendering report: A critical error occurred while trying to execute the render command: An error occurred while trying to start daemonized process: An error has occurred when trying to initialize jsreport (2). EBUSY: resource busy or locked, open 'C:\WINDOWS\TEMP\jsreport\compile\jsreport-2.2.0-r17qQMiI7\chrome\chrome.dll' (1). caused by error (2) -> stack = Error: at instance.init.then.catch ([eval]:43623:29) at tryCatcher (jsreportRuntime.js:146030:23) at Promise._settlePromiseFromHandler (jsreportRuntime.js:145723:31) at Promise._settlePromise (jsreportRuntime.js:145780:18) at Promise._settlePromise0 (jsreportRuntime.js:145825:10) at Promise._settlePromises (jsreportRuntime.js:145900:18) at Async._drainQueue (jsreportRuntime.js:41845:16) at Async._drainQueues (jsreportRuntime.js:41855:10) at Immediate.Async.drainQueues (jsreportRuntime.js:41729:14) at runCallback (timers.js:794:20) at tryOnImmediate (timers.js:752:5) at processImmediate [as _immediateCallback] (timers.js:729:5)caused by error (1) -> meta = {"errno":-4082,"code":"EBUSY","syscall":"open","path":"C:\WINDOWS\TEMP\jsreport\compile\jsreport-2.2.0-r17qQMiI7\chrome\chrome.dll"}, stack = Error: (1). caused by error (1) -> stack = Error: at exports.NsSocket.socket.dataOnce ([eval]:44008:13) at exports.NsSocket.listener ([eval]:16744:10) at exports.NsSocket.EventEmitter.emit ([eval]:16832:22) at exports.NsSocket._onData ([eval]:86359:8) at Lazy. ([eval]:51602:13) at Lazy. ([eval]:51584:19) at emitTwo (events.js:126:13) at Lazy.emit (events.js:214:7) at Lazy. ([eval]:51585:22) at emitOne (events.js:116:13) at Lazy.emit (events.js:211:7) at yieldTo ([eval]:51692:18) at Function. ([eval]:51730:27) at Lazy. ([eval]:51698:21) at emitOne (events.js:116:13) at Lazy.emit (events.js:211:7)

最佳答案

需要在RegisterGlobalFilters的FilterConfig中配置,所以会在当前app文件夹下创建jsreport文件夹,这样jsreport.exe不会干扰其他实例。关键属性是 TempDirectory,它定义了临时文件夹的位置。此 TempDirectory 中的所有文件都是自动创建的。

public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
  filters.Add(new HandleErrorAttribute());

  var tempPath = Path.Combine(HttpRuntime.AppDomainAppPath, "jsreport");

  filters.Add(new JsReportFilterAttribute(new LocalReporting()
    .Configure(cfg =>
    {
      cfg.BaseUrlAsWorkingDirectory();
      cfg.TempDirectory = tempPath;
      return cfg;
    })
    .UseBinary(JsReportBinary.GetBinary())
    .AsUtility()
    .Create()));
}

关于c# - 如何设置 JsReport .NET 以使用当前应用程序文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54201338/

相关文章:

asp.net-mvc - 在 MVC 应用程序中构建 Web 服务 API (SOAP)?

asp.net-mvc - mvc 3 session 和授权属性

css - Asp.net MVC 在发布时更改 css

.net - IronScheme 是解释还是编译?它是否受益于 .NET Framework 优化?

c# - 在 C# 中,我应该重用函数/属性参数来计算更清晰的临时值还是创建临时变量?

c# - 在 C# 中解析天气预报数据(来自 NDFD)

c# - 如何提取 Expression<Func<T, TResult>> 查询中使用的属性并测试它们的值?

.NET Entity Framework "remembering"数据库名称不存在

.net - 当使用 SxS 和 list 文件时,.net 调用 COM 并调用其他 .net COM 对象是否有效

c# - 对象未序列化