標籤:
1、Cookie在用戶端的瀏覽器中以索引值對的形式儲存,且用戶端向伺服器發出請求時會自動帶上Cookie
,Cookie不能跨瀏覽器訪問
2、HttpCookie cookie = SetCookie(new HttpCookie("Age","30")),這種形式設定的Cookie的生命週期是瀏覽器的生命週期
3、HttpCookie cookie = SetCookie(new HttpCookie("Age","30"));
cookie.Expires=DateTime.Now.AddDay(1);//最大時限
這麼設定的話,Cookie的儲存時間最多可以儲存1天
4、static在.net framework 啟動並執行時候一直存在,就可以在伺服器端儲存,相當於Session
5、List<Person> list=new List<Person>();
JavaScriptSerializer jss=new JavaScriptSerializer ();
string json=jss.Serialize(list);//把list集合Json序列化
6、var person = JSON.parse(jss);(還需要引用json2.js,為了相容低版本的瀏覽器)
for(i=0;i<person.length;i++)//person是集合的話需要遍曆
{
var p = person[i];
alert(p.Name);
}
7、XSS跨站指令碼
8、CKEditor: var zhengwen = document.getElementById("ZhengWen");
CKEDITOR.repalce(zhengwen);
9、不要把圖片或檔案直接存到資料庫中,在資料庫中存放一個映射地址就行
10、//獲得瀏覽器上傳的檔案資訊(<input type="file" name="ProductImage"....)
HttpPostedFile productimg=context.Request.Files["ProductImage"];
//如果表單中有input為image,則form要設定post和enctype
<form method="post" enctype="multipart/form-data"></form>
11、上傳的檔案為了防止重名,可以用Guid或者檔案內容的Md5值作為檔案名稱
12、http://test.com/aaa/a.htm
圖片路徑:image/a/jpg 表示在a.htm同檔案夾下的image檔案夾中 http://test.com/aaa/image/a/jpg
圖片路徑:/image/a/jpg 表示在根目錄檔案夾下的image檔案夾 http://test.com/image/a/jpg
13、在網路中傳輸資料用位元組數組
14、分頁:select *,row_number() over (order by id asc) as num from persons
15、天花板函數:Math.Ceiling(totalCount/10)
16、不要把DataTable等複雜物件直接通過Json傳遞給用戶端,一般應該只傳遞基本類型或者POCO(Plain Object c# Object,簡單的類,只有屬性的類)
17、DataTable dt=......
object[] comments = new object[dt.Rows.Count];
for(i=0;i<comments.Length;i++)
{
DataRow dr = dt.Rows[i];
comments[i] = new { Title=dr["Title"],Msg = dr["Msg"]};
}
string json = new JavaScriptSerializer().Serialize(comments);
context.Response.Write(json);
18、this.GetType()擷取當前執行個體的對象的類型
ASP.NET特輯筆記