【发布时间】:2017-10-19 06:58:31
【问题描述】:
我需要在我的网络服务中读取一个 csv 文件,
这是我目前的代码:
[WebMethod]
public List<string> getIdentifiants()
{
List<string> listA = new List<string>();
List<string> listB = new List<string>();
using (var fs = File.OpenRead(@"C:\Users\stag01\Desktop\identifiants.csv"))
using (var reader = new StreamReader(fs))
{
while (!reader.EndOfStream)
{
var line = reader.ReadLine();
var values = line.Split(';');
listA.Add(values[0]);
listB.Add(values[1]);
}
}
return listA;
}
但是当我尝试运行它时,我得到了这个错误:
System.Security.SecurityException: Échec de la demande d'autorisation de type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'。
à System.Security.CodeAccessSecurityEngine.Check(对象需求, StackCrawlMark& stackMark, Boolean isPermSet)
à System.Security.CodeAccessPermission.Demand()
à System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
à System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
à System.IO.File.OpenRead(字符串路径)
à WebApplication1.WS_stage_2017.getIdentifiants() dans \Nas-server\User Folder\stag01\Mes documents\Visual Studio 2017\Projects\WebApplication1\WebApplication1\WS_stage_2017.asmx.cs:ligne 31
谁能帮帮我?
【问题讨论】:
-
您的应用程序以有限的权限运行,您在测试时应该拥有完整的管理员帐户
标签: c# csv securityexception