gpt4 book ai didi

c# - Web.config 文件错误

转载 作者:行者123 更新时间:2023-11-30 12:16:15 24 4
gpt4 key购买 nike

我通过 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>

我收到运行时错误:

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"。这里有什么问题?我正在使用带有 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。

关于c# - Web.config 文件错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5717608/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com