2012-09-21 26 views
0

我開始使用MiniProfiler,並發現它在開發我的MVC 4應用程序時非常有用。MiniProfiler拋出異常「路徑中的非法字符」

但是,我只是添加了一個新的控制器動作和視圖到一個相當複雜的項目,現在MiniProfiler在控制器返回控制器後拋出一個異常。

例外文本是路徑中的非法字符

調用堆棧位置

MiniProfiler.dll!StackExchange.Profiling.MVCHelpers.ProfilingActionFilter.OnActionExecuted(System.Web.Mvc.ActionExecutedContext filterContext)線58

我控制器行動和觀點都很簡單。

控制器動作

[AllowAnonymous] 
    public ActionResult ReleaseNotes(string name) 
    { 
     CheckInput(name); 

     string notesPath = Server.MapPath("~/Content/ReleaseNotes/" + name + ".html"); 
     string notes = null; 

     if (System.IO.File.Exists(notesPath)) 
     { 
      notes = System.IO.File.ReadAllText(notesPath); 
     } 

     return View(notes); 
    } 

    private void CheckInput(string name) 
    { 
     if (name.Length > 0x100 || !name.IsAlphaNumeric()) throw new ArgumentException("Name is invalid."); 
    } 

注:System.IO.File.ReadAllText成功讀取HTML文件的內容。該路徑是有效的。

查看

@model string 

@{ 
    ViewBag.Title = "Release Notes"; 
} 

<h2>Release Notes</h2> 

@if (string.IsNullOrWhiteSpace(Model)) 
{ 
    <p>No release notes were found for the specified release.</p> 
} 
else 
{ 
    @Html.Raw(Model) 
} 

我有殘疾MiniProfiler現在。有關如何讓它再次運作的任何想法?

回答

0

事實證明,這個錯誤是這個問題

Illegal characters in path when calling the index view from my controller

我傳遞一個字符串作爲模型的一個奇怪的表現。由於方法重載的解決方式,MVC認爲HTML文件的內容是我想要加載的視圖的名稱(難怪它抱怨路徑...)。

有趣的是,調試器一直持續到拋出異常之前我的控制器動作返回。在禁用MiniProfiler之後,我的應用程序的全局異常處理程序捕獲並記錄了具體細節。

我還不確定爲什麼問題出現在MiniProfiler中。

相關問題