【问题标题】:404 page shown as source when debug=true in web.config (chrome and ff, not in edge)当 web.config 中的 debug=true 时,404 页面显示为源(chrome 和 ff,不在边缘)
【发布时间】:2018-05-24 17:24:26
【问题描述】:

当我收到一个不存在的路由请求时,在我的 mvc 应用程序中, 我清除服务器错误并重定向到我的 ErrorController(代码在 Global.asax.cs Application_Error):

Response.Clear();
HttpContext.Current.Response.TrySkipIisCustomErrors = true;

Server.ClearError();

var routeData = new RouteData();
routeData.Values.Add("controller", "Error");
routeData.Values.Add("action", "HttpError404");

IController errorController = new ErrorController();
errorController.Execute(new RequestContext(
     new HttpContextWrapper(Context), routeData));

并且动作返回一个视图:

public ActionResult HttpError404(Exception error)
{
    Response.StatusCode = 404;

    if (Request.IsAjaxRequest())
    {
        return Content("404 not found");
    }

    return View();
}

问题是当 chrome 和 ff(不在边缘)的 web.config 中有 compilation debug="true" 时,404 页面显示为源(纯 html)

【问题讨论】:

  • compilation与此无关...检查是否为您启用了浏览器链接,禁用并检查

标签: asp.net-mvc


【解决方案1】:

compilation 与特定于浏览器的东西无关。

但是从您的实现看来,浏览器链接导致了这个问题。

您可以禁用browser link 并检查它是否有效,

https://docs.microsoft.com/en-us/aspnet/visual-studio/overview/2013/using-browser-link#disabling

【讨论】:

    猜你喜欢
    • 2021-11-08
    • 2017-10-28
    • 2019-12-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-10
    相关资源
    最近更新 更多