可以直接修改,修改後立即生效,無需重新編譯,可以把資料連線對象直接加到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>