【问题标题】:How do I change the default path of IIS Express?如何更改 IIS Express 的默认路径?
【发布时间】:2019-10-16 08:38:57
【问题描述】:

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

代码sn-p:

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

【问题讨论】:

  • 您能否添加您正在编写的代码的sn-p,我们将为您提供建议。如果您也标记您正在使用的语言,您可能会获得更多帮助。谢谢

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


【解决方案1】:

请尝试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());
}

【讨论】:

  • 那行得通,但你的意思是说没有这个就无法更改 IIS Express 的设置?啊,还有一个额外的问题:当不在 IIS Express 上运行时,脚本的相对目录是什么?只是他们在项目中的位置?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-02-14
  • 1970-01-01
  • 2010-09-17
  • 1970-01-01
  • 2019-12-03
  • 2021-06-19
  • 2015-11-12
相关资源
最近更新 更多