設定檔 web.config 的討論

來源:互聯網
上載者:User

可以直接修改,修改後立即生效,無需重新編譯,可以把資料連線對象直接加到web.config 中,從而方便修改,如果寫在類中的話,

修改後需要重新編譯

1、所有的配置都必須放在<configuration></configuration>之間,

2、<appsettings>  </appsettings>之間是使用者自訂配置,一般用來設定一些常量;

<add></add>用來添加常量,key 是常量的名稱,value 是常量的值,程式中可以用

System.Configuration.ConfigurationSettings.AppSettings["key"] 來引用

如下面一個資料庫連接的例子----------
]<appSettings>
<add key="con" value="server=127.0.0.1;database=dat;sa=sa;pwd=sa"/>
 </appSettings>
在其它頁面可以用
SqlConnection con=new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["con"]);
       con.Open();
       SqlCommand cmd = new SqlCommand("select * from me", con);
       this.GridView1.DataSource = cmd.ExecuteReader();
       this.GridView1.DataBind();

這樣修改起來就很方便,不用每次修改後重新編譯,效果和class是一樣的。

3、<location></location> 是地區標記 path="a"表示下面的標記只對目錄a起作用。

4、<system.web></system.web>是關於整個應用程式的配置
如 在裡面設定緩衝

<pages buffer="true"/>//緩衝啟用(資料全部處理好 之前先先把處理好了緩衝在伺服器上,否則處理一點發送一點‘以16K為一單元’),預設情況下啟用緩衝
下面這個設定檔出錯時轉到一個專門的出錯頁面,mode="RemoteOnly" 表示在伺服器端可以看見詳細資料,其他的轉到一個專門的頁面。

如果 mode=“on” 則伺服器和客戶段都指向GenericErrorPage.htm
 <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
            <error statusCode="403" redirect="NoAccess.htm" />
            <error statusCode="404" redirect="FileNotFound.htm" />
        </customErrors>

<compilation debug="true">編譯時間的配置,debug="true"便於調試,但發布時要改成false

身分識別驗證:  <authentication mode="Windows"/>預設基於windows驗證,有4種 windows, forms,non,passport ,我們一般用基於forms(cookies 和session)的 
<authentication mode="Forms">
      <forms loginUrl="login.asp" name="boyang" protection="All"></forms> 
</authentication>
    <authorization>
      <deny users="?,a"/>不容許匿名和a
      <allow users ="b"/>b 可以
    </authentication>  

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.