【发布时间】:2011-05-28 13:41:51
【问题描述】:
我的代码:
[WebMethod]
public string HelloWorld()
{
string path = @"D:\Data\wwwroot\MyService\MyService\log.txt";
if (File.Exists(path))
{
using (StreamWriter sw = new StreamWriter(path))
{
sw.Write("Some sample text for the file");
return "wrote to a file";
}
}
else
{
return "file doesnt exist";
}
}
我得到的是: System.UnauthorizedAccessException:对路径“D:\Data\wwwroot\MyService\MyService\log.txt”的访问被拒绝。 在 System.IO.__Error.WinIOError(Int32 错误代码,字符串可能全路径) 在 System.IO.FileStream.Init(字符串路径、FileMode 模式、FileAccess 访问、Int32 权限、Boolean useRights、FileShare 共享、Int32 bufferSize、FileOptions 选项、SECURITY_ATTRIBUTES secAttrs、String msgPath、Boolean bFromProxy) 在 System.IO.FileStream..ctor(字符串路径、FileMode 模式、FileAccess 访问、FileShare 共享、Int32 bufferSize、FileOptions 选项) 在 System.IO.StreamWriter.CreateFile(字符串路径,布尔附加) 在 System.IO.StreamWriter..ctor(字符串路径,布尔附加,编码编码,Int32 缓冲区大小) 在 System.IO.StreamWriter..ctor(字符串路径) 在 D:\Data\wwwroot\MyService\MyService\Service.asmx.cs:line 29 中的 LinkTagOutWebService.Service1.HelloWorld() 处
我需要任何安全设置吗?日志文件设置为red/write....
【问题讨论】:
标签: web-services security file-io