【发布时间】:2020-09-11 11:30:00
【问题描述】:
我第一次在我的 Windows Server 2016 上部署了新的 ASP.NET Core 3.1 应用程序。但是,应用程序在启动时崩溃,并在 appsettings.json 加密期间引发 500.30 错误和异常。正如您在下面的 sn-p 中看到的,File.Exists 返回 true,但是,在 File.Encrypt 中会引发异常。我已确保在 IIS 的应用程序池中定义的用户帐户对文件夹具有完全控制权,但它似乎没有任何效果。
private static void EncryptAppSettings()
{
var path = Path.Combine(AppContext.BaseDirectory, "appsettings.json");
if (File.Exists(path))
{
File.Encrypt(path); // Unhandled exception. System.IO.IOException: Element not found. : 'P:\Balsam\appsettings.json'
}
}
文件本身当然存在于指定路径下。 来自事件查看器的完整信息:
Application: Balsam.Front.exe
CoreCLR Version: 4.700.20.41105
.NET Core Version: 3.1.8
Description: The process was terminated due to an unhandled exception.
Exception Info: System.IO.IOException: Element not found. : 'P:\Balsam\appsettings.json'
at System.IO.FileSystem.ThrowExceptionEncryptDecryptFail(String fullPath)
at System.IO.FileSystem.Encrypt(String path)
at System.IO.File.Encrypt(String path)
at Balsam.Front.Program.EncryptAppSettings() in P:\JENKINS\x\Balsam.Front\Program.cs:line 40
at Balsam.Front.Program.Main(String[] args) in P:\JENKINS\x\Balsam.Front\Program.cs:line 16
如果File.Exists 返回true,为什么File.Encrypt 会抛出异常?
【问题讨论】:
-
这是一个seemingly related bug in .Net Core(虽然现在应该已经修复了)。
-
服务用户拥有文件夹/文件的读取和写入权限?
-
@Fildor 是的,我可以设置的每个权限都已设置。
标签: c# asp.net-core io