2011-04-19 84 views
4

我通過godaddy.com主辦的網站,這是鏈接:的Web.config文件錯誤

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> 

我出現運行時錯誤:

Runtime Error

Description: An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine.

我還設置了customErrors mode =「off」。這裏有什麼問題?我在其中使用Visual Studio 2010 4.0框架。謝謝!

+0

什麼是運行時錯誤? – skaz 2011-04-19 14:08:17

+0

我編輯了我的問題。請見! – 2011-04-19 14:10:53

+0

您確定customErrors off是在服務器上提交的嗎?如果模式確實關閉,您應該會看到錯誤。 – skaz 2011-04-19 14:16:58

回答

1

服務器的machine.configapplicationHost.config可能會覆蓋您的web.config設置。不幸的是,如果真是這樣的話,沒有什麼事情可以做,因爲沒有聯繫GoDaddy的支持熱線。

+0

這是真的,但共享主機方案鎖定該特定配置設置似乎很奇怪。 – 2011-04-19 14:19:38

+0

謝謝你。我會盡力與他們聯繫。 – 2011-04-19 14:21:42

+0

聽起來有點嚴厲,從他們那裏。我不會將它們用於託管,因此我無法確認或否認這一點。 – 2011-04-19 14:26:49

0

customErrorsmodeOff我認爲是區分大小寫的。請檢查您是否有第一個字母大寫。

+0

我也看到了,但它看起來像OP在發佈的XML中有正確的內容(問題後面發佈的是不是) – Brook 2011-04-19 14:27:54

+0

我檢查了這一點。似乎是正確的! – 2011-04-19 14:38:43

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,這也是一個很好的功能。

+0

好的建議使用Elmah!只需nuget安裝elmah。 – 2011-04-19 15:03:00

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