Bra*_*ann 12 .net permissions clickonce .net-3.5
我开发了一个.net 3.0应用程序,它使用clickonce部署.
我想从完全信任转向部分信任以简化部署.
我在visual studio的项目"安全"选项卡中尝试了"计算权限"工具,答案非常明确:
---------------------------
Microsoft Visual Studio
---------------------------
This application requires full trust to run correctly.
Run Code Online (Sandbox Code Playgroud)
但是,我无法弄清楚为什么需要完全信任.我试图将安全设置更改为"部分信任",但应用程序在启动时立即引发SecurityException:
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()
Run Code Online (Sandbox Code Playgroud)
我的软件可能不需要完全信任(我只使用https连接到网络服务器,并且仅在用户请求时访问文件系统,用于导入/导出目的)
如何弄清楚我的应用程序需要完全信任的原因?
Bra*_*ann 10
看来我的问题是由于我的装配强烈签名.
引自msdn
在强名称程序集中,LinkDemand应用于其中所有可公开访问的方法,属性和事件,以限制它们用于完全信任的调用者.要禁用此功能,必须应用AllowPartiallyTrustedCallersAttributeattribute.
我正在为我的程序集添加所需的属性,我会告诉你事情的结果:
[assembly:AllowPartiallyTrustedCallers]
Run Code Online (Sandbox Code Playgroud)
更新:我已将属性添加到我的程序集,但我也使用了一些.net程序集.
并非所有.net程序集都可以被部分受信任的程序集使用(这里是列表),即WCF程序集(即System.ServiceModel)不在列表中
但是,Microsoft声明可以在部分信任环境中使用WCF(请参阅此处)
我试图从我的引用中删除所有不需要的程序集,我在所有程序集中都使用了AllowPartiallyTrustedCallers,但我仍然被卡住了......
在 app.config 的 configsections 中添加 requirePermission='false' 属性有很大帮助:
<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>
Run Code Online (Sandbox Code Playgroud)
这对我来说是个窍门!
| 归档时间: |
|
| 查看次数: |
16631 次 |
| 最近记录: |