如何:創建 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 配置的安全。

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