【问题标题】:MiniProfiler throws Exception "Illegal Character in Path"MiniProfiler 抛出异常“路径中的非法字符”
【发布时间】:2012-09-21 09:38:26
【问题描述】:

我开始使用MiniProfiler,发现它在开发我的 MVC 4 应用程序时非常有用。

但是,我刚刚在一个相当复杂的项目中添加了一个新的控制器操作和视图,现在 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。关于如何让它再次工作的任何想法?

【问题讨论】:

    标签: mvc-mini-profiler


    【解决方案1】:

    事实证明,这个错误是这个问题的一个奇怪表现

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

    我传入了一个字符串作为模型。由于方法重载的解析方式,MVC 认为 HTML 文件的内容是我要加载的视图的名称(难怪它抱怨路径...)。

    有趣的是,调试器一直持续到我的控制器操作返回,然后才抛出异常。在我禁用 MiniProfiler 后,我的应用程序的全局异常处理程序捕获并记录了细节。

    我仍然不确定为什么问题会出现在 MiniProfiler 中。

    【讨论】:

      猜你喜欢
      • 2022-12-17
      • 1970-01-01
      • 2014-04-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-28
      • 2017-10-17
      相关资源
      最近更新 更多