I have this public FileResult
method that if it finds the file I want to return it. If the file is missing I want to Redirect the users to the login page. Is there a way to do this?
Error is can't convert Redirect to file results
[HttpGet]
public FileResult GetFile(string fileManagerGuidId,string accessGroup)
var FileInfo = GetFile(fileManagerGuidId);
if (FileInfo != null)
{
FileManagerLog _filemanagerLog = new FileManagerLog();
_filemanagerLog.CustomerId =Request.Cookies["customerid"] != null ?
Convert.ToInt32(Request.Cookies["customerid"].Value) : 0;
_filemanagerLog.FileManagerGuid = new Guid(fileManagerGuidId);
SaveFileManagerLog(_filemanagerLog);
byte[] fileBytes = FileInfo.FileData;
return File(fileBytes, System.Net.Mime.MediaTypeNames.Application.Octet,
FileInfo.FileName);
}
else
{
return Redirect("~/Login");
}
}
CodePudding user response:
The method is defined to explicitly return a FileResult
:
public FileResult GetFile(string fileManagerGuidId,string accessGroup)
Since you also want to potentially return other results, the return type needs to be more generic, something from which the different result types inherit:
public ActionResult GetFile(string fileManagerGuidId,string accessGroup)