NPOI dll(第三方excel writer dll)…System.Security。SecurityException:该程序集不允许部分受信任的调用者

时间:2021-07-21 03:11:01

I had developed portal on Asp.net mvc framework.I had hosted this site at godaddy hosting.I had a great problem on integrating third party dll i.e. NPOI (excel writer dll).It dispaly following error.

我在Asp.net mvc框架上开发了门户。我在godaddy主持这个网站。我在集成第三方dll(即NPOI (excel writer dll)时遇到了一个很大的问题。它显示以下错误。

Security Exception

安全例外

**Description**: *The application attempted to perform an operation not allowed by the security policy.  To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file.*

**Exception Detail*s**:* System.Security.SecurityException: That assembly does not allow partially trusted callers.

   **Source Error:**

    *An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.*

Stack Trace:

堆栈跟踪:

[SecurityException: That assembly does not allow partially trusted callers.]
   ETravel.Web.Modules.Travel.Controllers.Admin.ReportController.TravelTaxList() in ReportController.cs:853
   lambda_method(ExecutionScope , ControllerBase , Object[] ) +39
   System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +17
   System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +178
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +24
   System.Web.Mvc.<>c__DisplayClassa.<InvokeActionMethodWithFilters>b__7() +52
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +254
   System.Web.Mvc.<>c__DisplayClassc.<InvokeActionMethodWithFilters>b__9() +19
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +254
   System.Web.Mvc.<>c__DisplayClassc.<InvokeActionMethodWithFilters>b__9() +19
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +254
   System.Web.Mvc.<>c__DisplayClassc.<InvokeActionMethodWithFilters>b__9() +19
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +192
   System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +399
   System.Web.Mvc.Controller.ExecuteCore() +126
   System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +27
   System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +7
   System.Web.Mvc.MvcHandler.ProcessRequest(HttpContextBase httpContext) +151
   System.Web.Mvc.MvcHandler.ProcessRequest(HttpContext httpContext) +57
   System.Web.Mvc.MvcHandler.System.Web.IHttpHandler.ProcessRequest(HttpContext httpContext) +7
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +181
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75

To solve this problem i had added this code line in web.config file.

为了解决这个问题,我在web中添加了这个代码行。配置文件。

<compilation debug="true">
   <assemblies>
.....................    .............
        <add assembly ="NPOI, Version=1.2.1.0, Culture=neutral, PublicKeyToken=0df73ec7942b34e1"/>
        <add assembly="NPOI.POIFS, Version=1.2.1.0, Culture=neutral, PublicKeyToken=0df73ec7942b34e1"/>
        <add assembly ="NPOI.HPSF, Version=1.2.1.0, Culture=neutral, PublicKeyToken=0df73ec7942b34e1"/>
        <add assembly ="NPOI.Util, Version=1.2.1.0, Culture=neutral, PublicKeyToken=0df73ec7942b34e1"/>
   </assemblies>
  </compilation>

And [assembly: AllowPartiallyTrustedCallers()] to Assemblyinfo.cs. But worn't work.what's the main problem and what is the solution???Pls help me...

和[汇编:允许托管调用者()]到汇编信息。cs。但穿不工作。主要问题是什么,解决方法是什么?请帮我…

1 个解决方案

#1


1  

No, it's NPOI that needs to allow partially trusted callers. It's probably doing something under-the-covers that won't work in a medium trust environment.

不,是NPOI需要允许部分可信的调用者。它可能是在一个中等信任的环境下做一些不为人知的事情。

Looking at the NPOI website it looks like it was updated to run in medium trust environments towards the end of last year, but that was after the 1.2.1 release. You should try the latest version, 1.2.3 beta, to see if that update has made it in and if that will fix it for you.

看看NPOI的网站,它看起来像是在去年年底被升级到在中等信任环境下运行,但那是在1.2.1版本之后。你应该试试最新的版本1.2.3 beta,看看这个更新是否成功了,是否能帮你修复。

#1


1  

No, it's NPOI that needs to allow partially trusted callers. It's probably doing something under-the-covers that won't work in a medium trust environment.

不,是NPOI需要允许部分可信的调用者。它可能是在一个中等信任的环境下做一些不为人知的事情。

Looking at the NPOI website it looks like it was updated to run in medium trust environments towards the end of last year, but that was after the 1.2.1 release. You should try the latest version, 1.2.3 beta, to see if that update has made it in and if that will fix it for you.

看看NPOI的网站,它看起来像是在去年年底被升级到在中等信任环境下运行,但那是在1.2.1版本之后。你应该试试最新的版本1.2.3 beta,看看这个更新是否成功了,是否能帮你修复。