如何更改IIS Express的默认路径?

时间:2019-05-30 16:56:09

标签: c# asp.net-mvc visual-studio iis-express

简单来说,如何更改IIS Express用来写入文件的默认路径,等等。 当前设置为C:\ Program Files(x86)\ IIS Express。
注意:我正在使用Visual Studio2019。

代码段:

System.IO.File.WriteAllText(@"file1.txt", "Test!");

1 个答案:

答案 0 :(得分:0)

请尝试https://docs.microsoft.com/en-us/dotnet/api/system.io.directory.setcurrentdirectory?view=netcore-2.2

 public static void Main()
    {
    // Create string for a directory. This value should be an existing directory
    // or the sample will throw a DirectoryNotFoundException.
      string dir = @"C:\test";      
      try
      {
          //Set the current directory.
          Directory.SetCurrentDirectory(dir);
      }
      catch (DirectoryNotFoundException e)
      {
          Console.WriteLine("The specified directory does not exist. {0}", e);
      }
    // Print to console the results.
      Console.WriteLine("Root directory: {0}", Directory.GetDirectoryRoot(dir));
      Console.WriteLine("Current directory: {0}", Directory.GetCurrentDirectory());
}