问题描述
我们现在看到的运行从NET4.0下一个网络共享下的应用程序时,一个很奇怪的问题。当指定的 defaultProxy 一节的的app.config 的一个 System.Net.WebException 被抛出。从一个本地驱动器运行时,是没有问题的。
据文件的应用程序将是完全信任的程序集运行一个网络共享,以便我们假设这应该只是罚款。
任何想法,我们如何才能解决这个问题呢?
有其他人遇到这个问题还是没有人知道为什么会是这样吗?
示例程序
使用系统;
使用System.Net;
命名空间ProxyTest
{
类节目
{
静态无效的主要(字串[] args)
{
尝试
{
字符串s =新的Web客户端()DownloadString(http://www.google.com)。
}
赶上(例外五)
{
Console.WriteLine(E);
}
}
}
}
的app.config
< XML版本=1.0&GT?;
<结构>
< system.net>
< defaultProxy useDefaultCredentials =真/>
< /system.net>
<启动>
< supportedRuntime版本=4.0版的SKU =NETFramework,版本= V4.0,外形=客户/>
< /启动>
< /结构>
异常详细信息
System.Net.WebException:一个Web客户端请求期间发生异常。 ---> System.Configuration.ConfigurationErrorsException:用于设置配置节defaultProxy权限不足。 ---> System.Security.SecurityException:请求类型的权限'System.Net.WebPermission,系统,版本= 4.0.0.0,文化=中性公钥= b77a5c561934e089失败。
在System.Security程序codeAccessSecurityEngine.Check(对象的需求,StackCrawlMark和放大器; stackMark,布尔isPermSet)。
在System.Security程序codeAccessSecurityEngine.Check(codeAccessPermission帽,StackCrawlMark和放大器; stackMark)。
在System.Security程序。codeAccessPermission.Demand()
在System.Net.Configuration.DefaultProxySection.PostDeserialize()
---内部异常堆栈跟踪的结尾---
在System.Configuration.BaseConfigurationRecord.EvaluateOne(字符串[]键,SectionInput的输入,布尔isTrusted,FactoryRecord factoryRecord,SectionRecord sectionRecord,对象parentResult)
在System.Configuration.BaseConfigurationRecord.Evaluate(FactoryRecord factoryRecord,SectionRecord sectionRecord,对象parentResult,布尔getLkg,布尔getRuntimeObject,对象和放大器;结果,对象和放大器; resultRuntimeObject)
在System.Configuration.BaseConfigurationRecord.GetSectionRecursive(字符串configKey,布尔getLkg,布尔的checkPermission,布尔getRuntimeObject,布尔requestIsHere,对象和放大器;结果,对象和放大器; resultRuntimeObject)
在System.Configuration.BaseConfigurationRecord.GetSectionRecursive(字符串configKey,布尔getLkg,布尔的checkPermission,布尔getRuntimeObject,布尔requestIsHere,对象和放大器;结果,对象和放大器; resultRuntimeObject)
在System.Configuration.BaseConfigurationRecord.GetSectionRecursive(字符串configKey,布尔getLkg,布尔的checkPermission,布尔getRuntimeObject,布尔requestIsHere,对象和放大器;结果,对象和放大器; resultRuntimeObject)
在System.Configuration.BaseConfigurationRecord.GetSection(字符串configKey,布尔getLkg,布尔的checkPermission)
在System.Configuration.BaseConfigurationRecord.GetSection(字符串configKey)
在System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(String sectionName)
在System.Configuration.ConfigurationManager.GetSection(字符串sectionName)
在System.Configuration.PrivilegedConfigurationManager.GetSection(字符串sectionName)
在System.Net.Configuration.DefaultProxySectionInternal.GetSection()
在System.Net.WebRequest.get_InternalDefaultWebProxy()
在System.Net.HttpWebRequest..ctor(URI URI,的ServicePoint服务点)
在System.Net.Htt prequestCreator.Create(URI URI)
在System.Net.WebRequest.Create(URI requestUri,布尔useUriBase)
在System.Net.WebRequest.Create(URI requestUri)
在System.Net.WebClient.GetWebRequest(URI地址)
在System.Net.WebClient.DownloadDataInternal(URI地址,WebRequest的&放大器;要求)
---内部异常堆栈跟踪的结尾---
在System.Net.WebClient.DownloadDataInternal(URI地址,WebRequest的&放大器;要求)
在System.Net.WebClient.DownloadString(URI地址)
在System.Net.WebClient.DownloadString(字符串地址)
在ProxyTest.Program.Main(字串[] args)的Y:\的Program.cs:行12
请参阅这的Microsoft知识库文章:
症状:
原因:
您可以从该网站要求的修补程序。
We're seeing a very strange issue when running the following application from a network share under NET4.0. When specifying a defaultProxy section in app.config a System.Net.WebException is thrown. There is no problem when running from a local drive.
According to documentation applications will run as full-trust assemblies from a network share so we're assuming this should work just fine.
Any ideas how we can work around this problem?
Has anyone else experienced this issue or does anyone know why this might be happening?
Sample program
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);
}
}
}
}
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>
Exception details
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 the permission of type 'System.Net.WebPermission, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet)
at System.Security.CodeAccessSecurityEngine.Check(CodeAccessPermission cap, StackCrawlMark& stackMark)
at System.Security.CodeAccessPermission.Demand()
at System.Net.Configuration.DefaultProxySection.PostDeserialize()
--- End of inner exception stack trace ---
at System.Configuration.BaseConfigurationRecord.EvaluateOne(String[] keys, SectionInput input, Boolean isTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult)
at System.Configuration.BaseConfigurationRecord.Evaluate(FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult, Boolean getLkg, Boolean getRuntimeObject, Object& result, Object& resultRuntimeObject)
at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
at System.Configuration.BaseConfigurationRecord.GetSection(String configKey, Boolean getLkg, Boolean checkPermission)
at System.Configuration.BaseConfigurationRecord.GetSection(String configKey)
at System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(String sectionName)
at System.Configuration.ConfigurationManager.GetSection(String sectionName)
at System.Configuration.PrivilegedConfigurationManager.GetSection(String sectionName)
at System.Net.Configuration.DefaultProxySectionInternal.GetSection()
at System.Net.WebRequest.get_InternalDefaultWebProxy()
at System.Net.HttpWebRequest..ctor(Uri uri, ServicePoint servicePoint)
at System.Net.HttpRequestCreator.Create(Uri Uri)
at System.Net.WebRequest.Create(Uri requestUri, Boolean useUriBase)
at System.Net.WebRequest.Create(Uri requestUri)
at System.Net.WebClient.GetWebRequest(Uri address)
at System.Net.WebClient.DownloadDataInternal(Uri address, WebRequest& request)
--- End of inner exception stack trace ---
at System.Net.WebClient.DownloadDataInternal(Uri address, WebRequest& request)
at System.Net.WebClient.DownloadString(Uri address)
at System.Net.WebClient.DownloadString(String address)
at ProxyTest.Program.Main(String[] args) in Y:\Program.cs:line 12
See this Microsoft Knowledge Base article:
Symptoms:
Cause:
You can request the hotfix from that site.
这篇关于从运行网络共享NET4.0应用程序时,在app.config中的异常指定defaultProxy时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!