web.config文件变更指南

时间:2013-11-03 11:44:52

标签: c# sql web-config

大家好,你们好吗?我是学生,并使用sql server 2005学习asp.net c#visual studio 2010.我开发了一个拥有数据库的网站。我开发了这个网站,自学从互联网上获取帮助。该网站已完成并在我的电脑中完美运行。

我已经注册了托管服务器和域名。

问题是,当我上传我的网站时,它无法正常显示以下错误:

Server Error in '/' Application.

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. 

Details: To enable the details of this specific error message to be viewable on remote machines, please create a <customErrors> tag within a "web.config" configuration file located in the root directory of the current web application. This <customErrors> tag should then have its "mode" attribute set to "Off".


<!-- Web.Config Configuration File -->

<configuration>
    <system.web>
        <customErrors mode="Off"/>
    </system.web>
</configuration>

Notes: The current error page you are seeing can be replaced by a custom error page by modifying the "defaultRedirect" attribute of the application's <customErrors> configuration tag to point to a custom error page URL.


<!-- Web.Config Configuration File -->

<configuration>
    <system.web>
        <customErrors mode="RemoteOnly" defaultRedirect="mycustompage.htm"/>
    </system.web>
</configuration>

我在互联网上的某处读到,在将网站上传到托管服务器之前,我必须配置我的web.config文件。在我的网站中,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="SPConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\ShoppingPortal.mdf;Integrated Security=True;User Instance=True"
   providerName="System.Data.SqlClient" />
 </connectionStrings>
    <system.web>
        <trace enabled="true" localOnly="false" pageOutput="true" />
  <compilation debug="true" targetFramework="4.0"/>
    </system.web>
</configuration>

我不知道我应该在其中编辑什么才能让它在托管服务器上工作,请在这方面帮助我,我该怎么办呢。提前谢谢

1 个答案:

答案 0 :(得分:2)

你得到的错误是一般性错误,说basicall,“有错误”。要找出错误是什么,ASP.NET要求您将配置设置添加到web.config文件的<system.web>部分。

默认情况下,<customerErrors> mode设置为RemoteOnly。这意味着如果您在本地浏览站点(使用localhost),则只能看到完整错误。

因此,要找出错误是什么,请将其添加到<system.web>部分的web.config中:

<system.web>
    <customErrors mode="Off" />
</system.web>

这将向您显示实际的错误消息,然后您可以修复它(或发布另一个问题:))。

确保在修复错误后将此设置更改为On。否则,您将向远程用户显示完整的堆栈错误跟踪。

此文档为here