Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# MVC 3、Elmah和view';错误';或者它的主人没有找到_C#_Asp.net Mvc 3_Elmah - Fatal编程技术网

C# MVC 3、Elmah和view';错误';或者它的主人没有找到

C# MVC 3、Elmah和view';错误';或者它的主人没有找到,c#,asp.net-mvc-3,elmah,C#,Asp.net Mvc 3,Elmah,我正在开发一个使用MVC 3、elmah和nhibernate的传统网站。Elmah日志实际上有数千个“视图‘错误’或其主文件未找到”错误。我认为这是在掩盖真正的错误。我不知道如何让Elmah记录真正的错误 为了尝试调试,我添加了-return-RedirectToAction(“noWhere”);-强迫犯错误。在本地,我会看到一个.net屏幕,上面简单地说“处理您的请求时发生异常…”在登台时,我会看到YOSOD屏幕,告诉我设置web.config customerrors节点。两者都将cus

我正在开发一个使用MVC 3、elmah和nhibernate的传统网站。Elmah日志实际上有数千个“视图‘错误’或其主文件未找到”错误。我认为这是在掩盖真正的错误。我不知道如何让Elmah记录真正的错误

为了尝试调试,我添加了-return-RedirectToAction(“noWhere”);-强迫犯错误。在本地,我会看到一个.net屏幕,上面简单地说“处理您的请求时发生异常…”在登台时,我会看到YOSOD屏幕,告诉我设置web.config customerrors节点。两者都将customerrors设置为on

web配置具有以下功能:

 <pages>
  <namespaces>
    <add namespace="System.Web.Mvc" />
    <add namespace="System.Web.Mvc.Ajax" />
    <add namespace="System.Web.Mvc.Html" />
    <add namespace="System.Web.Routing" />
    <add namespace="System.Web.Helpers" />
    <add namespace="System.Web.WebPages" />
  </namespaces>
</pages>
<httpModules>
  <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" />
  <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" />
  <add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" />
</httpModules>


  <customErrors mode="On" defaultRedirect="~/Views/Shared/PageNotFound">
      <error statusCode="404" redirect="~/Views/Shared/PageNotFound" />
      <error statusCode="500" redirect="~/Views/Shared/PageNotFound" />
  </customErrors>
Elmah班有

public class ElmahHandleErrorAttribute : System.Web.Mvc.HandleErrorAttribute 
{
    public override void OnException(ExceptionContext context)         
    {             
        base.OnException(context);               
        var e = context.Exception;             
        if (!context.ExceptionHandled // if unhandled, will be logged anyhow      
            || RaiseErrorSignal(e)    // prefer signaling, if possible 
            || IsFiltered(context))   // filtered?
            return;               
        LogException(e);         
    }  
baseController类具有:

protected ViewResult PageNotFound()
    {
        Response.StatusCode = (int)HttpStatusCode.NotFound;

        return View("PageNotFound", PageViewModelBuilder.UpdateSiteProperties(new PageViewModel()));
    }

    protected ViewResult PageBadRequest()
    {
        Response.StatusCode = (int)HttpStatusCode.BadRequest;
        return View("PageNotFound", PageViewModelBuilder.UpdateSiteProperties(new PageViewModel()));
    }

如果您能帮助记录正确的错误,我们将不胜感激。…

请将
“~/Views/Shared/PageNotFound”
更改为
“~/Views/Shared/PageNotFound.aspx”
(或
“~/Views/Shared/PageNotFound.chtml”
)在您的web.config中,确保您的
共享
文件夹中有
PageNotFound.aspx

是的,然后将其更改为该文件夹。我已经编辑了我的答案。它解决了你的问题吗?如果有,请标记为答案。谢谢-但是添加cshtml会导致抛出httpexception,并且不会影响原始问题您现在得到的httpexception是什么?我认为如果您解决了错误,elmah将只在System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute-statusCode=“404”处记录相关的real erros.System.Web.HttpException
protected ViewResult PageNotFound()
    {
        Response.StatusCode = (int)HttpStatusCode.NotFound;

        return View("PageNotFound", PageViewModelBuilder.UpdateSiteProperties(new PageViewModel()));
    }

    protected ViewResult PageBadRequest()
    {
        Response.StatusCode = (int)HttpStatusCode.BadRequest;
        return View("PageNotFound", PageViewModelBuilder.UpdateSiteProperties(new PageViewModel()));
    }