1

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: cli

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: ak

the views are:

v

So what is the reason of this difference between the results? and how can i avoid this error?

4

2 回答 2

2

除了这一行之外,这两个操作是相同的:

Response.Redirect("/Client/Index" + path + "/");

对比

Response.Redirect("/Akeo/Index" + path + "/");

所以我怀疑代码本身有很多问题。

你没有Exception从代码中得到一个,你从 IIS 得到一个 404 错误,如“页面未找到”。检查您的文件夹和父文件夹下的文件夹中是否都有Index视图文件,并且您正在使用正确的名称调用您的操作。ClientAkeoViews

于 2013-06-05T12:45:27.273 回答
1

在第一个控制器中,它正在 Views\Client\Index 文件夹中寻找视图:dotPeek-1.0..2545。第二个控制器正在寻找视图:Views\Akeo\Index 文件夹中的 dotPeek-1.0..2545。

看看你是否在第二个文件夹中有这个文件

于 2013-06-05T12:50:21.453 回答