2013-06-05 59 views
1

写作网址我在我的asp.net MVC应用程序url一个问题: 我有两个控制器,两个动作。 在控制器Client有一个asp.net MVC应用程序

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"); 
     } 

结果是: cli

但在控制器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"); 
     } 

结果是这样一个例外: ak

的观点是:

v

那么,什么是结果之间的差异的原因是什么?我怎样才能避免这个错误?

回答

2

两个动作,除了这条线相同的:

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

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

所以我怀疑有多少错误的代码本身。

你没有得到从代码的Exception,你从IIS得到一个404错误,如“找不到网页”。请检查您是否在既有Client文件夹的视图Index文件和文件夹AkeoViews文件夹下,并且你正在调用正确的名称你的行动。

+0

PLZ看到我的编辑 –

+0

看风景PLZ http://pastebin.com/SMhbnWtg –

+1

MVC,可以让你浏览到的路径和调用之间混淆了'索引'行动。你能发布你的路由配置吗? –

1

在第一控制器,它正在寻找一个观点:dotPeek-1.0..2545在视图\客户端\索引文件夹。 寻找视图中的第二个控制器:Views \ Akeo \ Index文件夹中的dotPeek-1.0..2545。

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

+0

没有dotPeek-1.0..2545它不是不是视图 –

+0

PLZ看到的视图http://pastebin.com/SMhbnWtg –

相关问题