问题描述:ASP.NET Core MVC无法编辑现有用户配置文件。
解决方法:
App_Data
文件夹中,可以使用以下代码获取文件的物理路径:string filePath = Path.Combine(Directory.GetCurrentDirectory(), "App_Data", "user.config");
var fileInfo = new FileInfo(filePath);
if (!fileInfo.Exists)
{
// 文件不存在,创建文件并设置访问权限
using (fileInfo.Create()) { }
fileInfo.Attributes = FileAttributes.Normal;
}
else
{
// 文件存在,检查并设置访问权限
fileInfo.Attributes = FileAttributes.Normal;
}
File
类提供的方法来读取和写入用户配置文件。以下是一个示例代码:// 读取用户配置文件
string content = File.ReadAllText(filePath);
// 编辑用户配置文件
content += "new config data";
// 写入用户配置文件
File.WriteAllText(filePath, content);
请根据您的具体需求和文件路径进行相应的修改。