Web.config文件错误

4
我正在通过godaddy.com托管一个网站,这是链接:http://floridaroadrunners.com/,这是我的web.config文件:
 <?xml version="1.0"?>

<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->

<configuration>
  <connectionStrings>
    <add name="ApplicationServices"
         connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true"
         providerName="System.Data.SqlClient" />
  </connectionStrings>

  <system.web>
    <compilation debug="true" targetFramework="4.0" />

    <authentication mode="Forms">
      <forms loginUrl="~/Account/Login.aspx" timeout="2880" />
    </authentication>

<customErrors mode="Off"/>

    <membership>
      <providers>
        <clear/>
        <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices"
             enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false"
             maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10"
             applicationName="/" />
      </providers>
    </membership>

    <profile>
      <providers>
        <clear/>
        <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/"/>
      </providers>
    </profile>

    <roleManager enabled="false">
      <providers>
        <clear/>
        <add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/" />
        <add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/" />
      </providers>
    </roleManager>

  </system.web>

  <system.webServer>
     <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
</configuration>

我遇到了运行时错误:

运行时错误

描述:服务器上发生应用程序错误。当前的自定义错误设置阻止远程查看应用程序错误的详细信息(出于安全原因)。但是,在运行在本地服务器机器上的浏览器中,可以查看它。

我已经将customErrors模式设置为“off”。这里出了什么问题?我正在使用带有4.0框架的Visual Studio 2010。谢谢!


你确定在服务器上关闭了customErrors吗?如果模式真的是关闭的,你应该能看到错误信息。 - skaz
当我遇到这种情况时,通常是由于web.config格式本身存在错误,导致配置无法解析。你发布的内容看起来没问题,所以我不知道... - Andrew Barber
4个回答

2
如果您的主机启用了customErrors,您可能需要自己捕获和记录异常,以便查看发生了什么。
有几个选择。首先,尝试使用Elmah
其次,您可以使用日志库(我喜欢NLog,但任何都可以),并在Global.asax.cs中捕获Application_Error事件。
protected void Application_Error(object sender, EventArgs e)
        {
            //first, find the exception.  any exceptions caught here will be wrapped
            //by an httpunhandledexception, which doesn't realy help us, so we'll
            //try to get the inner exception
            Exception exception = Server.GetLastError();
            if (exception.GetType() == typeof(HttpUnhandledException) && exception.InnerException != null)
            {
                exception = exception.InnerException;
            }

            //get a logger from the container
            ILogger logger = ObjectFactory.GetInstance<ILogger>();
            //log it
            logger.FatalException("Global Exception", exception);
        }

无论如何,这都是一个很好的功能,即使您能够关闭customErrors。

使用Elmah是个好建议!只需要nuget安装elmah即可。 - Pure.Krome

1

服务器的 machine.config 或者 applicationHost.config 很可能覆盖了你的 web.config 设置。如果是这种情况,很遗憾你无法做什么,除非联系 GoDaddy 的支持热线。


没错,但在共享托管场景中锁定该特定配置设置似乎很奇怪。 - Andrew Barber
那听起来有点严厉,来自他们。我不用他们的托管服务,所以无法确认或否认。 - Pure.Krome
我目前不使用它们,也从未使用过它们;我只是得出了最合理的结论,而没有对它们的政策进行猜测。 - Brian Driscoll

0
你可以在Global.asax中捕获错误并发送带有异常信息的电子邮件。
在Global.asax.cs文件中:
 void Application_Error(object sender, EventArgs e)
        {
            // Code that runs when an unhandled error occurs
            Exception ex = Server.GetLastError();
            ExceptionHandler.SendExceptionEmail(ex, "Unhandled", this.User.Identity.Name, this.Request.RawUrl);
            Response.Redirect("~/ErrorPage.aspx"); // So the user does not see the ASP.net Error Message
        }

我的ExceptionHandler类中的方法:

class ExceptionHandler
    {
        public static void SendExceptionEmail(Exception ex, string ErrorLocation, string UserName, string url)
        {
            SmtpClient mailclient = new SmtpClient();
            try
            {
                string errorMessage = string.Format("User: {0}\r\nURL: {1}\r\n=====================\r\n{2}", UserName, url, AddExceptionText(ex));
                mailclient.Send(ConfigurationManager.AppSettings["ErrorFromEmailAddress"],
                                ConfigurationManager.AppSettings["ErrorEmailAddress"],
                                ConfigurationManager.AppSettings["ErrorEmailSubject"] + " = " + ErrorLocation,
                                errorMessage);
            }
            catch { }
            finally { mailclient.Dispose(); }
        }

        private static string AddExceptionText(Exception ex)
        {
            string innermessage = string.Empty;
            if (ex.InnerException != null)
            {
                innermessage = string.Format("=======InnerException====== \r\n{0}", ExceptionHandler.AddExceptionText(ex.InnerException));
            }
            string message = string.Format("Message: {0}\r\nSource: {1}\r\nStack:\r\n{2}\r\n\r\n{3}", ex.Message, ex.Source, ex.StackTrace, innermessage);
            return message;
        }
    }

0

customErrors 我认为modeOff是区分大小写的。请检查您是否将第一个字符大写。


我也看到了,但是从发布的 XML 中可以看出大小写是正确的(问题后面发布的不是)。 - Brook

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接