小编Kar*_*son的帖子

从网络共享运行NET4.0应用程序时在app.config中指定defaultProxy时出现异常

从NET4.0下的网络共享运行以下应用程序时,我们看到一个非常奇怪的问题.当指定一个defaultProxy在部分的app.config一个System.Net.WebException被抛出.从本地驱动器运行时没有问题.

根据文档,应用程序将作为来自网络共享的完全信任程序集运行,因此我们假设这应该可以正常工作.

有什么想法我们如何解决这个问题?

有没有其他人遇到过这个问题,或者有人知道为什么会这样吗?

示例程序

using System;
using System.Net;

namespace ProxyTest
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                String s = new WebClient().DownloadString("http://www.google.com");
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

的app.config

  <?xml version="1.0"?>
  <configuration>
    <system.net>
      <defaultProxy useDefaultCredentials="true"/>
    </system.net>
    <startup>
      <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0,Profile=Client"/>
    </startup>
  </configuration>
Run Code Online (Sandbox Code Playgroud)

例外细节

System.Net.WebException: An exception occurred during a WebClient request. ---> System.Configuration.ConfigurationErrorsException: Insufficient permissions for setting the configuration section 'defaultProxy'. ---> System.Security.SecurityException: Request for …
Run Code Online (Sandbox Code Playgroud)

app-config exception network-share .net-4.0 defaultproxy

10
推荐指数
2
解决办法
1万
查看次数