为什么我的 .net 应用程序需要完全信任? [英] Why does my .net application require full trust?
问题描述
我开发了一个 .net 3.0 应用程序,该应用程序使用 clickonce 进行部署.
I've developed a .net 3.0 application, which is deployed using clickonce.
我想从完全信任转变为部分信任以简化部署.
I'd like to move from full trust to partial trust to ease deployment.
我已经在visual studio下我的项目的安全"选项卡中尝试了计算权限"工具,答案很清楚:
I've tried the "Calculate Permissions" tool in the "Security" tab of my project under visual studio, and the answer is quite clear :
---------------------------
Microsoft Visual Studio
---------------------------
This application requires full trust to run correctly.
但是,我一直无法弄清楚为什么需要完全信任.我尝试将安全设置更改为部分信任",但应用程序在启动时立即引发 SecurityException:
However, I've not been able to figure out why full trust is required. I've tried to change the security settings to "partial trust", but the application raises a SecurityException immediately upon launch :
System.Security.SecurityException {"Request failed.", Action= "System.Security.Permissions.SecurityAction.LinkDemand"
at MyNameSpace.Program.Main(String[] args)
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
at System.Runtime.Hosting.ManifestRunner.Run(Boolean checkAptModel)
at System.Runtime.Hosting.ManifestRunner.ExecuteAsAssembly()
at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext, String[] activationCustomData)
at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext)
at System.Activator.CreateInstance(ActivationContext activationContext)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.runTryCode(Object userData)
at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
我的软件可能不需要完全信任(我只使用 https 连接到网络服务器,并且仅根据用户请求访问文件系统,用于导入/导出目的)
My software probably doesn't need full trust (I only connect to a webserver using https, and access the filesystem only upon user request, for importation/exportation purposes)
我如何弄清楚为什么我的应用程序需要完全信任?
How can I figure out why my application requires full trust?
推荐答案
在 app.config 的配置部分中添加 requirePermission='false' 属性有很大帮助:
Adding the requirePermission='false' attribute in the app.config's configsections helps a lot :
<sectionGroup name="system.net" type="System.Net.Configuration.NetSectionGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section requirePermission="false" name="defaultProxy" type="System.Net.Configuration.DefaultProxySection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
</sectionGroup>
这对我来说很成功!
这篇关于为什么我的 .net 应用程序需要完全信任?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!