2014年3月26日 星期三

UrlEncode & UrlDecode in ASP.NET

From : http://www.dotblogs.com.tw/alonstar/archive/2010/01/04/12778.aspx


前陣子還看到蠻常有人在問這二個問題的,結果發現自己習慣用的和別人不太一樣:我比較常用Server.UrlEncode,不過有些人習慣的是HttpUtility.UrlEncode;這二個差別可以從程式碼看得出來…
HttpServerUtility的預設編碼模式是從Response截取,而HttpUtility則是預設UTF8,我們通常都用UTF8編碼,所以沒什麼差;如果不是利用UTF8編碼的時候,使用上就要小心一點。
01//Server.UrlEncode
02public sealed class HttpServerUtility
03{
04 
05    public string UrlEncode(string s)
06    {
07        Encoding e = (this._context != null) ? this._context.Response.ContentEncoding : Encoding.UTF8;
08        return HttpUtility.UrlEncode(s, e);
09    }
10 
11    public string UrlDecode(string s)
12    {
13        Encoding e = (this._context != null) ? this._context.Request.ContentEncoding : Encoding.UTF8;
14        return HttpUtility.UrlDecode(s, e);
15    }
16 
17}
18 
19//HttpUtility.UrlEncode
20public sealed class HttpUtility
21{
22    public static string UrlEncode(string str)
23    {
24        if (str == null)
25        {
26            return null;
27        }
28        return UrlEncode(str, Encoding.UTF8);
29    }
30     
31    public static string UrlDecode(string str)
32    {
33        if (str == null)
34        {
35            return null;
36        }
37        return UrlDecode(str, Encoding.UTF8);
38    }
39  
40}

2014年3月13日 星期四

CSS 屬性 Display 的值 Inline Block Inline-block None

Form : http://john24318.github.io/blog/2013/03/09/css-shu-xing-display-de-zhi-inline-block-inline-block-none/


常用的4種display:
1. display: none
2. display: inline (ex: <a>、<span>、<b>、<i>、<img>、<iframe>…)
3.display: block (ex: <div>、<p>、<h1>、<h2>…)
4.display: inline-block
1. display: none
把 HTML 元件的 display 設為 none 就是不顯示這個東西。display: none 和 visibility: hidden 的差別是 display: none 這個東西就不見了,不佔空間,visibility: hidden 只是隱形看不見,還是有佔空間。
2. display: inline
<a>、<span>、<b>、<i>、<img>、<iframe>… 這幾個 HTML 元素預設的 display 屬性是 inline,用最簡單的講法解釋 display: inline 就是兩個 display: inline 的元素連在一起會在同一行,不會換行。
display: inline 的 HTML 元素可以有 margin-left、margin-right、padding-left、padding-right,但不能有 margin-top、margin-bottom、padding-top、padding-bottom、width、heightbackground-image 。
要讓 display: inline 元素水平置中的方式是在此元素的父元素加上 text-align: center。
※當然你也可以用 CSS 把預設是 display: inline 的 HTML 元素設成 display: block 。
附帶一提,display: inline 元素不該包住 display: block 元素。
3.display: block
<div>、<p>、<h1>、<h2>… 這幾種 HTML 元素預設的 display 屬性是 block ,簡單講就是不管 display: block 元素的前面後面是什麼,碰到 display: block 元素就是會換行,而 display: block 元素的寬度預設會撐到最大。
display: block 元素不管是 margin、padding、width、height、background-image 通通都可以。
要將 display: block 元素水平置中,方法是在此元素加上 margin: 0 auto, 0 可以取代為任何數字。
※當然也可以用 CSS 把預設是 display: block 的 HTML 元素設成 display: inline 。
4.display: inline-block
顧名思義,就是外面是 inline,裡面是 block 。
所以碰到 display: inline-block 元素不會換行,但是又可以設定 padding-top、padding-bottom、width、height、background-image。
用 CSS 讓連結用圖片顯示就是 inline-block 常見的應用。

2014年3月7日 星期五

Google Page Speed Online 測試網站速度的工具

利用 Google Page Speed Online 測試網站速度並提供建議來最佳化

http://developers.google.com/speed/pagespeed/insights/




Pingdom Tools


Pingdom 是一間提供伺服器、網絡、和網站的檢查服務的公司,它的免費線上網站速度測試工具,提供幾個頗有用的報告,包括網頁中每一個物件的下載時間 (如圖像、樣式表、和 JavaScript 程式庫),和流覽器還存的效能級別等,還有一個很有用的網頁分析報告,提供諸如下載時間、網頁大小和請求訊息等。




WebPagetest

這個漂亮的線上工具測試網頁在真實瀏覽器的渲染速度 (Chrome、Firefox 和 IE),並讓你選擇來自世界各地的數個地點進行測試,它還可以模擬不同的互聯網連接速度 (例如 DSL 及 56K 撥號上網),更可以選擇性地攔截廣告,使你知道那些廣告對網頁的效能負擔有多大。



 

MangoHost Copyright © 2009 Cookiez is Designed by Ipietoon for Free Blogger Template