我编写了一些代码,用于从FTP服务器读取文本文件,而无需下载到本地系统。当我在本地运行它,它正常工作。但远程它显示错误:
System.Security.SecurityException:请求类型'System.Net.WebPermission,System,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089'的权限失败。
尽管有以下web.config:
<configuration>
<runtime>
<loadFromRemoteSources enabled="true" />
</runtime>
</configuration>
我的代码是
request.Credentials = new NetworkCredential("****", "*********");
byte[] newFileData = request.DownloadData(url);
string fileString = System.Text.Encoding.UTF8.GetString(newFileData);
string[] score_details = fileString.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None);
foreach (var line in score_details)
{
ListBox1.Items.Add(line);
}