gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 03:09:19 24 4
gpt4 key购买 nike

从NET4.0下的网络共享中运行以下应用程序时,我们看到一个非常奇怪的问题。在app.config中指定 defaultProxy 部分时,将抛出 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);
}
}
}
}

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)详情
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

最佳答案

请参阅this Microsoft知识库文章:

症状:

  • You run a Microsoft .NET Framework 4-based application that is stored on a network share.
  • The application calls a static method in the System.Configuration.ConfigurationManager class. For example, the application calls the ConfigurationManager.GetSection method.

In this scenario, a System.Security.SecurityException exception is thrown and then the application crashes.



原因:

The issue occurs because the method fails to access configuration section from the application on network share.



您可以从该站点请求此修补程序。

关于从网络共享运行NET4.0应用程序时在app.config中指定defaultProxy时发生异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8327691/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com