C# can';在asp core 2.1中上载后无法访问映像

C# can';在asp core 2.1中上载后无法访问映像,c#,asp.net,asp.net-mvc,asp.net-core,C#,Asp.net,Asp.net Mvc,Asp.net Core,上传后我无法访问照片进行查看。 这是上传代码 ` 公共异步任务上载\u映像(FormFile文件,字符串名称) { var newFileName=string.Empty; 如果(file.Length>0) { var fileName=string.Empty; string PathDB=string.Empty; //获取文件名 fileName=ContentDispositionHeaderValue.Parse(file.ContentDisposition.fileName.T

上传后我无法访问照片进行查看。
这是上传代码 `

公共异步任务上载\u映像(FormFile文件,字符串名称)
{
var newFileName=string.Empty;
如果(file.Length>0)
{
var fileName=string.Empty;
string PathDB=string.Empty;
//获取文件名
fileName=ContentDispositionHeaderValue.Parse(file.ContentDisposition.fileName.Trim(“”);
//分配唯一文件名(Guid)
var myUniqueFileName=Convert.ToString(Guid.NewGuid());
//获取文件扩展名
var FileExtension=Path.GetExtension(文件名);
//合并文件名+文件扩展名
newFileName=myUniqueFileName+FileExtension;
if(string.IsNullOrWhiteSpace(_env.WebRootPath))
{
_env.WebRootPath=Path.Combine(Directory.GetCurrentDirectory(),name);
}
//将两个字符串合并到一个路径中。
fileName=\u env.WebRootPath+'\\'+newFileName;
//若要在数据库中存储文件夹的路径
PathDB=name+“/”+newFileName;
newFileName=PathDB;
使用(FileStream fs=System.IO.File.Create(文件名))
{
等待文件.CopyToAsync(fs);
fs.Flush();
}
}
返回newFileName;
}`
我正在使用
ID
作为参数“name”的参数。
当我尝试使用“/ID/whatEverhere.jpg”访问照片时
return NOTFOUND????

将文件存储在以下位置:

 fileName = _env.WebRootPath + '\\' + newFileName;`  
 ...
 using (FileStream fs = System.IO.File.Create(fileName))
然后你返回:

PathDB = name+"/" + newFileName;
newFileName = PathDB;
...
return newFileName;
因此,这不是相同的路径,存储文件的路径中没有您的ID!
我觉得你应该清理你的代码

PathDB = name+"/" + newFileName;
newFileName = PathDB;
...
return newFileName;