如何:创建 Web.config 文件

Web.config 文件的创建,“添加新项”
  1. 键入小于号 (<) 开始一个新元素。

    出现一个下拉列表,该列表提供可在此插入点添加的有效元素。或者,也可以按“Ctrl+J”显示该下拉列表而无需键入小于号。

 

使用 IntelliSense 编辑配置设置

  1. 在 Visual Web Developer 中打开 Web.config 文件。

  2. 在编辑窗口中,将光标放在某行上的 <system.web> </system.web> 标记内,但不要放在其他任何标记内。

  3. 键入小于号 (<) 开始一个新元素。

    出现一个下拉列表,该列表提供可在此插入点添加的有效元素。或者,也可以按“Ctrl+J”显示该下拉列表而无需键入小于号。

  4. 选择“anonymousIdentification”。

    anonymousIdentification 元素(ASP.NET 设置架构)元素即放置在 Web.config 文件中并结束。如果元素是由结束标记结束的,则存在可设置的可用子元素。如果元素的结束方式与下面的 anonymousIdentification 元素相同,则不存在要设置的可用子元素。

      复制代码
    <anonymousIdentification />
  5. 将光标放在 <anonymousIdentification /> 标记内,然后按空格键。

    出现一个下拉列表,该列表提供可添加到 anonymousIdentification 元素的有效属性。或者,也可以按“Ctrl+J”显示该下拉列表而无需按空格键。

  6. 选择“启用”。

    enabled 属性被放置在 Web.config 文件中,由于它是一个布尔属性,在一个下拉列表中提供了 true 和 false 值。

  7. 选择“false”。这是系统默认值。

    IntelliSense 系统会提示插入点的可用元素和可用属性。有时不会提供专用属性。例如,在配置 siteMap 元素(ASP.NET 设置架构)等元素的 providers 元素时,可用属性是不同的,具体取决于要添加的提供程序的类型。IntelliSense 不显示这些属性,因为它们取决于 type 属性的值。

  8. 将 enabled 属性的值更改为无效值 "falsex"。

    IntelliSense 系统提供验证检查,并在所有未通过验证的文本下面显示一条波浪线。

示例

下面的代码示例演示 Visual Web Developer 创建的 Web.config 文件的初始内容。为 compilation 和 authentication 元素提供的是默认设置。若要启用 ASP.NET 调试,所需全部操作是将 compilation 元素的 debug 属性更改为 true。可以在 system.web 元素中出现的所有元素都在 ASP.NET 配置设置 中进行了说明。

  复制代码
<?xml version="1.0"?>
<!-- 
    Note: As an alternative to hand editing this file you can use the 
    Web Site Administration Tool to configure settings for your application. Use
    the Web site->Asp.Net Configuration option in Visual Studio.
    A full list of settings and comments can be found in 
    machine.config.comments usually located in 
    /Windows/Microsoft.Net/Framework/v2.x/Config 
-->
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
    <appSettings/>
    <connectionStrings/>
    <system.web>
        <!-- 
            Set compilation debug="true" to insert debugging 
            symbols into the compiled page. Because this 
            affects performance, set this value to true only 
            during development.
        -->
        <compilation debug="false"/>
        <!--
            The <authentication> section enables configuration 
            of the security authentication mode used by 
            ASP.NET to identify an incoming user. 
        -->
        <authentication mode="Windows"/>
        <!--
            The <customErrors> section enables configuration 
            of what to do if/when an unhandled error occurs 
            during the execution of a request. Specifically, 
            it enables developers to configure html error pages 
            to be displayed in place of a error stack trace.

        <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
            <error statusCode="403" redirect="NoAccess.htm"/>
            <error statusCode="404" redirect="FileNotFound.htm"/>
        </customErrors>
        -->
    </system.web>
</configuration>

安全

在应用程序的配置文件中存储敏感信息时,应使用受保护配置对敏感值进行加密。有关配置文件的这一问题以及其他安全问题的更多信息,请参见保证 ASP.NET 配置的安全。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章