【问题标题】:Running Winforms application from network share从网络共享运行 Winforms 应用程序
【发布时间】:2015-01-08 16:44:29
【问题描述】:

我有一个位于网络驱动器上的 .Net 应用程序,当启动它时,它立即崩溃。使用 WinDBG 分析日志,这是导致它的异常:

Exception object: 00000000027806c8
Exception type: System.Security.SecurityException
Message: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
InnerException: <none>
StackTrace (generated):
    SP               IP               Function
    000000000018BAC0 0000000000000001 mscorlib_ni!System.Security.CodeAccessSecurityEngine.Check(System.Object, System.Threading.StackCrawlMark ByRef, Boolean)+0x2
    000000000018BAC0 000007FEDFD88CC7 mscorlib_ni!System.Security.CodeAccessPermission.Demand()+0x37
    000000000018BB00 000007FEDFD8838D mscorlib_ni!System.AppDomainSetup.VerifyDir(System.String, Boolean)+0x8d
    000000000018BB50 000007FF001C119B NLog!NLog.Config.ConfigSectionHandler.System.Configuration.IConfigurationSectionHandler.Create(System.Object, System.Object, System.Xml.XmlNode)+0x18b
    000000000018BBD0 000007FEDE78EDC2 System_Configuration_ni!System.Configuration.RuntimeConfigurationRecord+RuntimeConfigurationFactory.CreateSectionImpl(System.Configuration.RuntimeConfigurationRecord, System.Configuration.FactoryRecord, System.Configuration.SectionRecord, System.Object, System.Configuration.ConfigXmlReader)+0x162
    000000000018BC20 000007FEDE784566 System_Configuration_ni!System.Configuration.RuntimeConfigurationRecord+RuntimeConfigurationFactory.CreateSectionWithRestrictedPermissions(System.Configuration.RuntimeConfigurationRecord, System.Configuration.FactoryRecord, System.Configuration.SectionRecord, System.Object, System.Configuration.ConfigXmlReader)+0x86
    000000000018BCA0 000007FEDE78EB4E System_Configuration_ni!System.Configuration.RuntimeConfigurationRecord.CreateSection(Boolean, System.Configuration.FactoryRecord, System.Configuration.SectionRecord, System.Object, System.Configuration.ConfigXmlReader)+0x5e
    000000000018BD10 000007FEDE78EA52 System_Configuration_ni!System.Configuration.BaseConfigurationRecord.CallCreateSection(Boolean, System.Configuration.FactoryRecord, System.Configuration.SectionRecord, System.Object, System.Configuration.ConfigXmlReader, System.String, Int32)+0x92

StackTraceString: <none>
HResult: 8013150a
SecurityException Message: 
The action that failed was:
Demand
The type of the first permission that failed was:
System.Security.Permissions.FileIOPermission
The first permission that failed was:
<IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
version="1"
PathDiscovery="\\172.16.27.229\Apps\MyApp.config"/>

我的应用程序没有定义 SNK,但它正在使用具有 SNK 的 NLog。 我还在 NLog 中添加了 [assembly: AllowPartiallyTrustedCallers],以便我的应用程序能够使用它。 使用运行时安全策略 mscorcfg.msc,我给了 NLog.dll FullTrust。 我也给了我的应用程序 FullTrust,但我使用的条件是通过发布者而不是强名称。也许这可能是问题所在,但从我在异常中得到的情况来看,我认为这与 MyApp.config 有关。

我错过了什么?

【问题讨论】:

  • 错误信息提示机器或用户账户没有足够的文件I/O权限。
  • 您的用户是否已读取相应 .config 文件的权限?
  • 此链接包含大量有关调试代码访问安全性的信息,emmet-gray.com/Articles/CodeAccessSecurity.html 有很多事情可能会出错。
  • 您的应用程序也必须进行签名,并且您的密钥和 NLog 的密钥都必须按照 Lynn 链接中的说明进行设置。加上您正在使用的程序集中的任何其他第三方密钥

标签: c# .net-2.0 file-permissions securityexception caspol


【解决方案1】:

找到了解决办法!

当然使用 SNK 很好,我相信这是解决问题的一种方法。

显然我遇到的问题是我尝试从 \\172.16.27.229 启动应用程序,而不是使用 \\MyNAS。 我通过评估给定程序集的权限来理解它。 当我使用带有 \\IP 的路径时,它几乎没有任何权限,但是当我使用 \\name 时,它​​获得了“无限制”权限。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-08
    相关资源
    最近更新 更多