Asp.net 将webservice部署为虚拟目录时出现权限问题。在VSIDE中工作

Asp.net 将webservice部署为虚拟目录时出现权限问题。在VSIDE中工作,asp.net,impersonation,permission-denied,Asp.net,Impersonation,Permission Denied,我有一个ASP.NET web服务,它将在路径中创建一个文本文件,该路径将作为参数传递给该方法 private void CreateFile(string path) { string strFileName = path; StreamWriter sw = new StreamWriter(strFileName, true); sw.WriteLine(""); sw.Write("Created at " + Date

我有一个ASP.NET web服务,它将在路径中创建一个文本文件,该路径将作为参数传递给该方法

 private void CreateFile(string path)
 {
        string strFileName = path;
        StreamWriter sw = new StreamWriter(strFileName, true);
        sw.WriteLine("");
        sw.Write("Created at " + DateTime.Now.ToString());
        sw.Close();
 }
现在,我在网络中传递一个文件夹作为参数并调用该方法

  CreateFile(@"\\192.168.0.40\\labels\\test.txt");
从VisualStudioIDE运行代码时,将在路径中创建文件。但当我发布并部署为虚拟目录时,它给我带来了一些错误,比如

   "System.UnauthorizedAccessException: Access to the path '\\192.168.0.40\labels\test.txt' is denied.
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at 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)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
   at System.IO.StreamWriter.CreateFile(String path, Boolean append)
   at System.IO.StreamWriter..ctor(String path, Boolean append, Encoding encoding, Int32 bufferSize)
   at System.IO.StreamWriter..ctor(String path, Boolean append)

我的
web.config中有
。我的机器运行在XP中,另一台运行在Windows Server 2003中。我已将该文件夹的写入权限设置为“任何人”。

您的web应用程序正在本地aspnet用户帐户下运行,该帐户无权访问网络上的资源。如果IIS版本中有应用程序池,则必须使应用程序池用户成为有权访问网络资源的域用户。如果没有应用程序池,请在web.config的元素中更改web的用户

您的web应用程序正在本地aspnet用户帐户下运行,该帐户无权访问网络上的资源。如果IIS版本中有应用程序池,则必须使应用程序池用户成为有权访问网络资源的域用户。如果没有应用程序池,请在web.config的元素中更改web的用户