Asp.net mvc ASP.NET MVC配置文件!允许调试

Asp.net mvc ASP.NET MVC配置文件!允许调试,asp.net-mvc,configuration,web-config,Asp.net Mvc,Configuration,Web Config,我也是stackOverflow和MVC3的新手 我托管了一个应用程序,它将我重定向到errorPage(InternalError.htm):正如我在配置文件中配置的那样!但我想更改此设置,以便显示错误消息,例如 line 23 : //exception Or Error here 有人能提醒我要添加的标签和属性吗?首次登场=真的???哪里等 亲切的问候 您可以使用customErrors mode=“RemoteOnly”,如果您在本地计算机上,您将看到错误 <system.web

我也是stackOverflow和MVC3的新手

我托管了一个应用程序,它将我重定向到errorPage(InternalError.htm):正如我在配置文件中配置的那样!但我想更改此设置,以便显示错误消息,例如

line 23 : //exception Or Error here
有人能提醒我要添加的标签和属性吗?首次登场=真的???哪里等
亲切的问候

您可以使用
customErrors mode=“RemoteOnly”
,如果您在本地计算机上,您将看到错误

<system.web>
    <customErrors mode="RemoteOnly" defaultRedirect="~/system/Error/FriendlyError">
      <error statusCode="403" redirect="~/system/Error/accessDenied" />
    </customErrors>
</system.web>

您正在查找customErrors属性()


在本地开发计算机上,您可以将其设置为
关闭
仅远程
。在生产机器上,将其设置为
On
RemoteOnly


在您的情况下,如果将其设置为
RemoteOnly
,则在将桌面远程到生产机器时可以看到异常详细信息。如果不可能,只需将其切换到
关闭

我使用了一个自定义错误处理程序

将以下代码添加到Global.asax.cs

    protected void Application_Error()
    {
        // if the debugger is attached, do not show the custom error page
        if (System.Diagnostics.Debugger.IsAttached)
        {
            return;
        }

        try
        {
            Exception exception = Server.GetLastError();
            Response.Clear();
            Server.ClearError();
            RouteData routeData = new RouteData();
            routeData.Values["controller"] = "MyCustomErrorController";
            routeData.Values["action"] = "Index";
            routeData.Values["exception"] = exception;

            IController errorsController = new MyCustomErrorController();
            var rc = new RequestContext(new HttpContextWrapper(Context), routeData);
            errorsController.Execute(rc);
        }
        catch (Exception ex)
        {
            // if an error occurs within this method, do nothing
            // app will automatically show the browser's default error page
        }
    }
我还将自定义代码添加到我的错误页面,以便在用户是超级用户时显示异常详细信息。因此,如果我没有处于调试模式或在现场,我可以很容易地看到错误详细信息(如果我以管理员身份登录)


要更好地理解代码,请通过谷歌搜索或使用调试器逐步完成。

谢谢,但这不是我想要的。我想在线查看syntax错误,比如:第23行://exception或error here。另外,请查看ELMAH:这是一个简单易用的错误记录器,您可以直接从Nuget软件包安装它:本地的详细错误如何?第23行://异常或错误此处是否部署调试或发布版本?对不起,沃特,我不再了解发布或调试版本是什么!我开发了一个asp.net mvc3应用程序,右键单击并选择了“发布/部署”选项卡。但是我想在线跟踪调试符号(应用程序所在地:www.mysite.com)!有什么想法吗?
    protected void Application_Error()
    {
        // if the debugger is attached, do not show the custom error page
        if (System.Diagnostics.Debugger.IsAttached)
        {
            return;
        }

        try
        {
            Exception exception = Server.GetLastError();
            Response.Clear();
            Server.ClearError();
            RouteData routeData = new RouteData();
            routeData.Values["controller"] = "MyCustomErrorController";
            routeData.Values["action"] = "Index";
            routeData.Values["exception"] = exception;

            IController errorsController = new MyCustomErrorController();
            var rc = new RequestContext(new HttpContextWrapper(Context), routeData);
            errorsController.Execute(rc);
        }
        catch (Exception ex)
        {
            // if an error occurs within this method, do nothing
            // app will automatically show the browser's default error page
        }
    }