I started using MiniProfiler and find it very useful while developing my MVC 4 application.
However, I just added a new controller action and view to a fairly complex project, and now MiniProfiler throws an Exception after control returns from the controller.
The exception text is Illegal Character in Path.
The Call stack location is
MiniProfiler.dll!StackExchange.Profiling.MVCHelpers.ProfilingActionFilter.OnActionExecuted(System.Web.Mvc.ActionExecutedContext filterContext) Line 58
My controller action and view are both quite simple.
Controller action
[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.");
}
NOTE: System.IO.File.ReadAllText successfully reads in the contents of an HTML file. That path is valid.
View
@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)
}
I have disabled MiniProfiler for now. Any thoughts on how to get it working again?
It turns out that this error was a curious manifestation of this issue
Illegal characters in path when calling the index view from my controller
I was passing in a string as the model. Due to the way method overloading resolves, MVC thought that the contents of the HTML file was the name of the view that I wanted to load (no wonder it complained about the path...).
Interestingly enough, the debugger continued until the return from my controller action before throwing the Exception. After I disabled MiniProfiler, my application's global exception handler caught and logged the specifics.
I'm still not sure why the problem showed up in MiniProfiler.