'UnauthorizedAccessException' - 'Global\.net clr networking'

moo*_*ogs 9 .net security

我正在用户Guest下测试我的应用程序.它崩溃时出现以下错误.

'UnauthorizedAccessException' - 'Global.net clr networking'

现在,我知道我可以编辑机器上的安全策略,以允许在guest虚拟机下运行的CLR代码受到信任,但是应该在商业应用程序上做什么?

(签名,并添加CAS属性?)我目前正在阅读整个安全部分,但我有时间捏,所以任何正确方向的指针都会受到赞赏.

编辑:我已经跟踪问题使用类Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.如果包含此项,则会显示错误.我正在寻找要添加到清单或其他方式的东西,以便在安装/运行应用程序时,它会要求相应的权限.我不想要求用户亲自调用caspol或其他工具.

环境详细信息: - 应用程序正在使用.NET 3.0 - 操作系统是Vista

以下是这些内容的相关堆栈跟踪:

Unhandled Exception: System.UnauthorizedAccessException: Access to the path 'Glo
bal\.net clr networking' is denied.
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.Threading.Mutex.<>c__DisplayClass3.<.ctor>b__0(Object userData)
   at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCl
eanup(TryCode code, CleanupCode backoutCode, Object userData)
   at System.Threading.Mutex..ctor(Boolean initiallyOwned, String name, Boolean&
 createdNew, MutexSecurity mutexSecurity)
   at System.Diagnostics.SharedUtils.EnterMutexWithoutGlobal(String mutexName, M
utex& mutex)
   at System.Diagnostics.SharedPerformanceCounter.Verify(CategoryEntry* currentC
ategoryPointer)
   at System.Diagnostics.SharedPerformanceCounter.FindCategory(CategoryEntry** r
eturnCategoryPointerReference)
   at System.Diagnostics.SharedPerformanceCounter.GetCounter(String counterName,
 String instanceName, Boolean enableReuse, PerformanceCounterInstanceLifetime li
fetime)
   at System.Diagnostics.SharedPerformanceCounter..ctor(String catName, String c
ounterName, String instanceName, PerformanceCounterInstanceLifetime lifetime)
   at System.Diagnostics.PerformanceCounter.Initialize()
   at System.Diagnostics.PerformanceCounter.set_RawValue(Int64 value)
   at System.Net.NetworkingPerfCounters.Initialize()
   at System.Net.Configuration.SettingsSectionInternal..ctor(SettingsSection sec
tion)
   at System.Net.Configuration.SettingsSectionInternal.get_Section()
   at System.Net.Sockets.Socket.InitializeSockets()
   at System.Net.Sockets.Socket.get_SupportsIPv4()
   at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.get_
HostName()
   at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Regi
sterChannel(Boolean SecureChannel)
   at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(
String[] commandLine)
Run Code Online (Sandbox Code Playgroud)

Mat*_*lis 5

是否可以将其添加到app.config文件中?

<configuration>
   <system.net>
      <settings>
         <performanceCounters enabled="false" />
      </settings>
   </system.net>
</configuration>
Run Code Online (Sandbox Code Playgroud)

这将指示网络类不要尝试创建在Guest帐户下不起作用的性能计数器.

上面的设置可以在.NET Framework 4及更高版本中运行,但是由于早期版本中的bug失败.

  • 所以看起来在.NET 2.0/3.0/3.5中,上面的设置只能防止数据被写入性能计数器,它实际上并没有阻止它们被创建(这是你看到这个错误的地方).但是,.NET Framework 4已解决此问题:http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeededID = 3874419 (2认同)