C# System.Security.SecurityException:该程序集不允许部分受信任的调用方
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/777041/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
System.Security.SecurityException: That assembly does not allow partially trusted callers
提问by
i am creating pdf by using itextsharp.dll, local it is working fine. but server am facing below error .i have added assemblyinfo.cs ..but same error is coming.Specifically, I modified the AssemblyInfo.cs file by adding these references and attribute:
我正在使用 itextsharp.dll 创建 pdf,本地它工作正常。但服务器面临以下错误。我添加了 assemblyinfo.cs ..但同样的错误即将到来。具体来说,我通过添加这些引用和属性修改了 AssemblyInfo.cs 文件:
using System.Security; using System.Security.Permissions; [assembly: AllowPartiallyTrustedCallers]
使用 System.Security;使用 System.Security.Permissions;[程序集:AllowPartiallyTrustedCallers]
in my form the pdf throws an error at myDocument.. It never go to read it n throws the below error...
在我的表单中,pdf 在 myDocument 中引发错误。
Document myDocument = new Document(PageSize.A4, 70, 70, 70, 70);
still am getting the error in server .. can anyone help me out
仍然在服务器中出现错误.. 谁能帮我
Server Error in '/' Application. 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 Details: System.Security.SecurityException: That assembly does not allow partially trusted callers.
异常详细信息:System.Security.SecurityException:该程序集不允许部分受信任的调用方。
Source Error:
源错误:
Line 216: HttpContext.Current.Response.End();
Line 217:
Line 218: }
Line 219: protected void droplist_SelectedIndexChanged(object sender, EventArgs e)
Line 220: {
第 216 行:HttpContext.Current.Response.End();第 217 行:
第 218 行:} 第 219 行:protected void droplist_SelectedIndexChanged(object sender, EventArgs e) 第 220 行:{
Source File: d:\hosting\bookgroupadmin\agent\checkbeforprintconf.aspx.cs Line: 218
源文件:d:\hosting\bookgroupadmin\agent\checkbeforprintconf.aspx.cs 行:218
Stack Trace:
堆栈跟踪:
[SecurityException: That assembly does not allow partially trusted callers.] finalgroup_checkbeforprintconf.btn_Click(Object sender, EventArgs e) in d:\hosting\bookgroupadmin\agent\checkbeforprintconf.aspx.cs:218 System.Web.UI.WebControls.Button.OnClick(EventArgs e) +105 System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +107 System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +7350 System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +213 System.Web.UI.Page.ProcessRequest() +86 System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) +18 System.Web.UI.Page.ProcessRequest(HttpContext context) +49 ASP.checkbeforprintconf_aspx.ProcessRequest(HttpContext context) in App_Web_ovcuievo.18.cs:0 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +358 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +64
[SecurityException:该程序集不允许部分受信任的调用方。] d:\hosting\bookgroupadmin\agent\checkbeforprintconf.aspx.cs:218 System.Web.UI.WebControls.Button 中的 finalgroup_checkbeforprintconf.btn_Click(Object sender, EventArgs e)。 OnClick(EventArgs e) +105 System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +107 System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7 System .Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +7350 System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint,Boolean includeStagesAfterAsyncPoint) +213 System.Web.UI.Page.ProcessRequest() +86 System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) +18 System.Web.UI.Page.ProcessRequest(HttpContext context) +49 ASP。 Checkbeforprintconf_aspx.ProcessRequest(HttpContext context) in App_Web_ovcuievo.18.cs:0 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +358 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&completedSynchronously) +64CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +358 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&completedSynchronously) +64CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +358 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&completedSynchronously) +64
Version Information: Microsoft .NET Framework Version:2.0.50727.1433; ASP.NET Version:2.0.50727.1433
版本信息:Microsoft .NET Framework 版本:2.0.50727.1433;ASP.NET 版本:2.0.50727.1433
回答by Slavo
Most probably the library that you use does not support a medium trust environment (most shared hosting companies). It might not be your code that throws the error, but the third party - make sure that they do support this.
您使用的库很可能不支持中等信任环境(大多数共享托管公司)。引发错误的可能不是您的代码,而是第三方 - 确保他们确实支持这一点。
If the stack trace ends in a portion of code written by you, then please provide this code, currently it is not clear what exactly doesn't have permissions to run.
如果堆栈跟踪以您编写的部分代码结束,那么请提供此代码,目前尚不清楚究竟是什么没有权限运行。
回答by Dotneter
The best thing about it though is that it can run in Medium trust mode - once a minor change is made to allow partially trusted callers. To make this change download the iTextSharp source distribution (http://sourceforge.net/projects/itextsharp/files/) Modify the AssemblyInfo.cs file to add the partially trusted callers attribute.
不过,它最好的一点是它可以在中等信任模式下运行 - 一旦进行了微小的更改以允许部分信任的调用者。要进行此更改,请下载 iTextSharp 源分发 ( http://sourceforge.net/projects/itextsharp/files/) 修改 AssemblyInfo.cs 文件以添加部分受信任的调用者属性。
[assembly: AllowPartiallyTrustedCallers()]
Rebuild the iTextSharp assembly and it should be good to go in a Medium trust environment.
重建 iTextSharp 程序集,进入中等信任环境应该会很好。
回答by Chathura
I got the same issue and it has solved by creating another folder, move all the contents to that and change the application path to the new folder. I can't say that how it solved fore sure. But it worked for me. I believe it has due to some caching issue in IIS.
我遇到了同样的问题,它通过创建另一个文件夹,将所有内容移动到该文件夹并将应用程序路径更改为新文件夹来解决。我不能肯定地说它是如何解决的。但它对我有用。我相信这是由于 IIS 中的一些缓存问题。
Hope this will help you guys.
希望这会帮助你们。
回答by Nripendra Ojha
I also faced this type problem and resolved by follow the instruction of below link. it is so helpful it save my 3 days hard work. You can try this
我也遇到了这种类型的问题,并按照以下链接的说明解决了。它是如此有用,它节省了我 3 天的辛勤工作。你可以试试这个
Last 2 more step doing by me which is not mentioned 1. Remove old reference of iTextsharp from your project. 2. Add new iTextsharp dll reference in your project. which is make by you. Then publish your project. Do not directly paste the new itextsharp.dll in your server with old publish code.
最后 2 步由我完成,但未提及 1. 从您的项目中删除 iTextsharp 的旧参考。2. 在您的项目中添加新的 iTextsharp dll 引用。这是你做的。然后发布您的项目。不要将新的 itextsharp.dll 与旧的发布代码直接粘贴到您的服务器中。