[英]Web.config File Error
我通過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。 謝謝!
如果您的主機已啟用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,這也是一個很好的功能。
服務器的machine.config
或applicationHost.config
可能會覆蓋您的web.config
設置。 不幸的是,如果不是這樣,那么除了聯系GoDaddy的支持熱線之外,沒有什么可以做的。
customErrors mode
值Off
我認為是區分大小寫的。 請檢查您是否有第一個字符大寫。
您可以捕獲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 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;
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.