I have a problem in url
in my asp.net mvc application :
i have two controllers with two actions.
in the controller Client
public ActionResult Index(string path)
{
if (CompteModels.Connected)
{
/*
ProjetModels projets = new ProjetModels();
List<string> _noms_de_projets = projets.GetProjectsFromClient(CompteModels.Id_connected);
return View(_noms_de_projets);
* */
string realPath;
realPath = "C:/Projets/" + path;
realPath = realPath.Replace("Index/", "");
if (System.IO.File.Exists(realPath))
{
return base.File(realPath, "application/octet-stream");
}
else if (System.IO.Directory.Exists(realPath))
{
Uri url = Request.Url;
if (url.ToString().Last() != '/')
{
Response.Redirect("/Client/Index" + path + "/");
}
List<DirModel> dirListModel = new List<DirModel>();
IEnumerable<string> dirList = Directory.EnumerateDirectories(realPath);
foreach (string dir in dirList)
{
DirectoryInfo d = new DirectoryInfo(dir);
DirModel dirModel = new DirModel();
dirModel.DirName = Path.GetFileName(dir);
dirModel.DirAccessed = d.LastAccessTime;
dirListModel.Add(dirModel);
}
List<FileModel> fileListModel = new List<FileModel>();
IEnumerable<string> fileList = Directory.EnumerateFiles(realPath);
foreach (string file in fileList)
{
FileInfo f = new FileInfo(file);
FileModel fileModel = new FileModel();
if (f.Extension.ToLower() != "php" && f.Extension.ToLower() != "aspx"
&& f.Extension.ToLower() != "asp")
{
fileModel.FileName = Path.GetFileName(file);
fileModel.FileAccessed = f.LastAccessTime;
fileModel.FileSizeText = (f.Length < 1024) ? f.Length.ToString() + " B" : f.Length / 1024 + " KB";
fileListModel.Add(fileModel);
}
}
ExplorerModel explorerModel = new ExplorerModel(dirListModel, fileListModel);
return View(explorerModel);
}
else
{
return Content(path + " is not a valid file or directory.");
}
}
else return RedirectToAction("Login", "Account");
}
the result is:
but in the controller Akeo
public ActionResult Index(string path)
{
if (CompteModels.Connected)
{
/*
ProjetModels projets = new ProjetModels();
List<string> _noms_de_projets = projets.GetProjectsFromClient(CompteModels.Id_connected);
return View(_noms_de_projets);
* */
string realPath;
realPath = "C:/Projets/" + path;
realPath = realPath.Replace("Index/", "");
if (System.IO.File.Exists(realPath))
{
return base.File(realPath, "application/octet-stream");
}
else if (System.IO.Directory.Exists(realPath))
{
Uri url = Request.Url;
if (url.ToString().Last() != '/')
{
Response.Redirect("/Akeo/Index" + path + "/");
}
List<DirModel> dirListModel = new List<DirModel>();
IEnumerable<string> dirList = Directory.EnumerateDirectories(realPath);
foreach (string dir in dirList)
{
DirectoryInfo d = new DirectoryInfo(dir);
DirModel dirModel = new DirModel();
dirModel.DirName = Path.GetFileName(dir);
dirModel.DirAccessed = d.LastAccessTime;
dirListModel.Add(dirModel);
}
List<FileModel> fileListModel = new List<FileModel>();
IEnumerable<string> fileList = Directory.EnumerateFiles(realPath);
foreach (string file in fileList)
{
FileInfo f = new FileInfo(file);
FileModel fileModel = new FileModel();
if (f.Extension.ToLower() != "php" && f.Extension.ToLower() != "aspx"
&& f.Extension.ToLower() != "asp")
{
fileModel.FileName = Path.GetFileName(file);
fileModel.FileAccessed = f.LastAccessTime;
fileModel.FileSizeText = (f.Length < 1024) ? f.Length.ToString() + " B" : f.Length / 1024 + " KB";
fileListModel.Add(fileModel);
}
}
ExplorerModel explorerModel = new ExplorerModel(dirListModel, fileListModel);
return View(explorerModel);
}
else
{
return Content(path + " is not a valid file or directory.");
}
}
else return RedirectToAction("Login", "Account");
}
the result is an exception like this:
the views are:
So what is the reason of this difference between the results? and how can i avoid this error?