我正在尝试从web api返回JSON文件内容。以下是我的代码:
string path = string.Empty;
path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory
.Substring(0,AppDomain.CurrentDomain.BaseDirectory.IndexOf("HostUrl")), fileName);
StreamReader file = File.OpenText(path);
return file.ReadToEnd();
工作正常。但有时我的文件名会出现404错误。 我尝试从生成的Url访问该文件,它加载完美。
这背后的原因是什么?