如何:创建 Web.config 文件

本文介绍了如何在Visual Web Developer中利用IntelliSense编辑Web.config文件,包括创建元素、选择属性以及进行验证检查。示例展示了配置文件的基本结构,强调了启用ASP.NET调试的方法,并提到了安全方面,如加密敏感信息的重要性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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 元素相同,则不存在要设置的可用子元素。

     CopyCode image复制代码
    <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 配置设置 中进行了说明。

 CopyCode image复制代码
<?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 配置的安全。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值