Web.config文件错误

时间:2011-04-19 14:04:42

标签: c# asp.net web-hosting web-deployment

我通过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 mode =“off”。这有什么不对?我正在使用带有4.0框架的Visual Studio 2010。谢谢!

4 个答案:

答案 0 :(得分: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,这也是一个很好的功能。

答案 1 :(得分:1)

服务器的machine.configapplicationHost.config可能会覆盖您的web.config设置。不幸的是,如果没有这种情况,那么除了联系GoDaddy的支持热线外,没有什么可以做的。

答案 2 :(得分:0)

我认为

customErrors modeOff区分大小写。请检查您是否有第一个字符大写。

答案 3 :(得分: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
        }

My ExceptionHandler Class中的方法:

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;
        }
    }