Hello, in .net core 6 "System.IO.File.WriteAllText(FilePath, Text)" after this method "return RedirectToAction(nameof(Index));"
I want to use it but I don't get any error or a return. It creates the file normally, but I can't redirect.
When I close the code block, my redirect works. What would be the reason ?
var DirectoryPath = _hostingEnvironment.WebRootPath + slashed + "menu";
var FileName = "anamenu.html";
var Text = html;
StringBuilder exportText = new StringBuilder(Text.ToString());
if (!Directory.Exists(DirectoryPath))
{
Directory.CreateDirectory(DirectoryPath);
}
string FilePath = DirectoryPath + slashed + FileName;
if (!File.Exists(FilePath))
{
File.WriteAllText(FilePath, Text);
}
else
{
try
{
File.WriteAllText(@FilePath, exportText.ToString());
}
catch (Exception ex)
{
//does not enter this field
throw;
}
}
//it also crosses this area but does not steer
return RedirectToAction(nameof(Index));