C# Web.config文件错误
我通过godaddy.com托管一个网站,链接如下: 这是我的web.config文件:C# Web.config文件错误,c#,asp.net,web-hosting,web-deployment,C#,Asp.net,Web Hosting,Web Deployment,我通过godaddy.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> &l
<?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”。这里怎么了?我正在使用Visual Studio 2010,其中包含4.0框架。谢谢 服务器的
machine.config
或applicationHost.config
可能会覆盖您的web.config
设置。不幸的是,如果是这样的话,除了联系GoDaddy的支持热线,你真的无能为力。模式
值关闭
我认为是区分大小写的。请检查你的第一个字符大写。 < P>如果你的主机已经启用了<代码> CudialError < /代码>,你可以考虑自己捕获和记录异常,这样你就可以看到发生了什么。
有两种选择。首先,试试看
其次,您可以使用日志库(我喜欢NLog,但任何日志库都可以),并在Global.asax.cs中捕获应用程序错误事件
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);
}
受保护的无效应用程序\u错误(对象发送方,事件参数e)
{
//首先,找到异常。在此捕获的任何异常都将被包装
//通过一个httpunhandledexception,它实际上对我们没有帮助,所以我们将
//尝试获取内部异常
Exception=Server.GetLastError();
if(exception.GetType()==typeof(HttpUnhandledException)&&exception.InnerException!=null)
{
exception=exception.InnerException;
}
//从容器中获取记录器
ILogger logger=ObjectFactory.GetInstance();
//记录下来
FatalException(“全局异常”,异常);
}
无论发生什么情况,这都是一个很好的功能,即使您能够关闭customErrors。您可以在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;
}
}
我编辑了我的问题。请看!是否确定已在服务器上提交customErrors off?如果模式真的关闭了,您应该会看到错误。当我遇到这种情况时,总是由于web.config格式本身的错误导致配置无法解析。你发布的内容看起来不错,所以我不知道……这是真的,但共享主机场景锁定特定的配置设置似乎很奇怪。从他们看来,这听起来有点苛刻。我不使用它们作为主机,所以我不能确认或否认这一点。我目前没有使用它们,也从来没有使用过它们;我只是得出了一个最有意义的结论,而不是对他们的政策进行真正的推测。我也看到了这一点,但看起来OP在发布的xml中的内容是正确的(问题后面发布的内容不是)使用Elmah的好建议!只需安装elmah。