ASP.NET特輯筆記

來源:互聯網
上載者:User

標籤:

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特輯筆記

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.