UWInfo Blog
發表新文章
[Join] | [忘記密碼] | [Login]
搜尋

搜尋意見
文章分類-darren
[所有文章分類]
  • ASP.NET (24)
  • ASP.NET2.0 (4)
  • ASP.NET4.0 (13)
  • JavaScript (17)
  • jQuery (5)
  • FireFox (2)
  • UW系統設定 (2)
  • SQL (7)
  • SQL 2008 (3)
  • mirror (0)
  • SVN (2)
  • IE (3)
  • IIS (6)
  • IIS6 (0)
  • 閒聊 (1)
  • W3C (4)
  • 作業系統 (3)
  • C# (14)
  • CSS (0)
  • FileServer (0)
  • HTML 5 (7)
  • CKEditor (0)
  • UW.dll (9)
  • Visual Studio (2)
  • Browser (2)
  • SEO (0)
  • Google Apps (1)
  • 網站輔助系統 (1)
  • DNS (0)
  • SMTP (3)
  • 網管 (5)
  • 社群API (3)
  • SSL (1)
  • App_Inventor (0)
  • URLRewrite (1)
  • 開發工具 (2)
  • JSON (0)
  • Excel2007 (0)
  • 試題 (0)
  • LINQ (0)
  • bootstrap (0)
  • Vue (0)
  • IIS7 (2)
  • foodpanda (0)
  • 編碼 (0)
  • 資安 (3)
  • Sourcetree (0)
  • MAUI (0)
  • CMD (0)
  • my sql (1)
所有文章分類
[darren的分類]
  • ASP.NET (48)
  • ASP.NET2.0 (15)
  • ASP.NET4.0 (34)
  • JavaScript (49)
  • jQuery (26)
  • FireFox (4)
  • UW系統設定 (3)
  • SQL (39)
  • SQL 2008 (25)
  • mirror (4)
  • SVN (4)
  • IE (9)
  • IIS (20)
  • IIS6 (1)
  • 閒聊 (7)
  • W3C (6)
  • 作業系統 (9)
  • C# (24)
  • CSS (12)
  • FileServer (1)
  • HTML 5 (11)
  • CKEditor (3)
  • UW.dll (13)
  • Visual Studio (16)
  • Browser (8)
  • SEO (1)
  • Google Apps (3)
  • 網站輔助系統 (4)
  • DNS (5)
  • SMTP (4)
  • 網管 (11)
  • 社群API (3)
  • SSL (4)
  • App_Inventor (1)
  • URLRewrite (2)
  • 開發工具 (6)
  • JSON (1)
  • Excel2007 (1)
  • 試題 (3)
  • LINQ (1)
  • bootstrap (0)
  • Vue (3)
  • IIS7 (3)
  • foodpanda (2)
  • 編碼 (2)
  • 資安 (3)
  • Sourcetree (1)
  • MAUI (1)
  • CMD (1)
  • my sql (1)
最新回應
  • IIS ARR (reverse proxy) 服務安裝
    ...more
  • UW DB 元件罕見的錯誤
    我之前好像也遇過, 考慮改一下 pg 的程式....more
  • UW DB物件 GetAllDataFromBaseTableWithCache 會嚴重影響效能
    我把它拿掉了....more
  • UW DB物件 GetAllDataFromBaseTableWithCache 會嚴重影響效能
    好, 把它拿掉.....more
  • 使用 facebook JS SDK 的心得筆記
    FB.login 沒有任何反應~ 不知道怎解決...more
  • IIS Server SSL 升級方式
    更新一版 reg 可以變 A...more
  • 防止 event 往上傳的終極方法
    eee...more
  • IIS Server SSL 升級方式
    Cool......more
  • UNT流量異常追蹤紀實
    有做 Request 的來源 IP 分析嗎 ? 說不定會有其它的發現.....more
  • facebook 網頁分享 Debug 模式
    Header 裡面的兩個 tag.. <meta property="og:i...more
標籤
  • fortinet
  • vpn
  • 排程
  • MSkvKiovQU
  • CS
  • 搜尋
  • ddd
  • 空格
  • 站內
  • minvalue[t
  • dbcontext
  • C
  • -5809
  • .
  • GRANT
  • who
  • ctcn
  • UW.JSON.Wr
  • 1
  • CK,
  • yh3IqUv4
  • 15421
  • 22
  • Encode
  • line pay介接
  • kill
  • json
  • inline
  • injection
  • inertsql
  • ses
  • iis7 的設定匯
  • iis 匯出
  • http 錯誤 40
  • http 錯èª
  • for
  • fdoug懶惰程式碼
  • dotnet
  • datatable
  • css 列印
  • IIS 設定 匯出
  • IIS 匯入
  • IIS匯出
  • 日期
  • 使用者對應
  • a
  • ad
  • 試題
  • GN
頁數 2 / 3 上一頁 下一頁
搜尋 結果:
Optional 參數使用 Date 格式所使用的預設值
VB.NET 時間類別因為沿襲自 VB,所以可以用 Date 型別宣告時間變數
實際上在 .NET 他等於 System.DateTime (C# 沒有 Date型別, 只有System.DateTime)
VB.NET 的 Date 可以設定常數,例如 #12/30/2014# (注意!格式是 MM/dd/yyyy, 用 #包起來),這是C#沒有的 
VB.NET 的 Date 也可以等於 Nothing (Nothing = #12:00:00 AM#)
C# 的 DateTime 可以指定為 default(DateTime) 但是不能 = null

由於 optional 參數必須指定預設值,因此當使用 Date 當作 optional 參數時就要設定以上說的值


Public Sub AddNewCustomer(customer As Customer, Optional dateAdded As Date = Nothing)
     If dateAdded = Nothing Then dateAdded = Now


// C# 4.0 以後的 function 已經可以使用 optional 參數
public void AddNewCustomer(Customer customer, DateTime dateAdded = default(DateTime))
     {
         if (dateAdded == default(DateTime)) dateAdded = DateTime.Now;
         ......


Public Sub AddNewCustomer(customer As Customer, Optional dateAdded As Date = #12/30/1899#)

 
More...
darren, 2014/4/1 下午 02:07:31
SqlDependency 之 Stored Procedure
SqlDependency 的原理是對某些目標 table 設定所謂的 ChangeId
資料存在 dob.[AspNet_SqlCacheTablesForChangeNotification]
當目標 Table 有 Insert, Update, Delete 時會 Trigger 把 ChangeId + 1
而前端網站就是不斷定時詢問此 [AspNet_SqlCacheTablesForChangeNotification] 的 ChangeId


-- 新增目標 Table 加入 SqlDependency (此範例 MenuFirst是 table name)
Exec dbo.AspNet_SqlCacheRegisterTableStoredProcedure N'MenuFirst'

-- 直接變更 ChangeId (效果等同於去變更該table資料)
-- 會去將 ChangeId + 1
EXEC dbo.AspNet_SqlCacheUpdateChangeIdStoredProcedure N'MenuFirst'


AspNet_SqlCacheUpdateChangeIdStoredProcedure 通常是不需要做的
因為目標table都有設定 Trigger
但是在某些狀況下 目標table資料沒有變更 但是也希望前端cache要更新
就可以用此 SP
 
More...
darren, 2014/1/21 下午 12:25:33
IndexOf 效能問題
一直覺得 UW.Template 應該還有改善的空間,因為網站大量使用這個物件
只要有一些些效能調教,對於整體效能應該有很大的幫助

昨天發現切版的程式 UW.Template => GetTemplateFromString
在使用 IndexOf 去尋找 <!--Key S--> 及 <!--Key E--> 時,
<!--Key E--> 可能有一些問題,因為他是從第0個位置開始找
而實際上他應該是從 <!--Key S--> 後面開始找比較對
所以後者的 IndexOf 要加個 StartIndex 參數值比較對


    StartP = StartP + StartKey.Length
    Dim EndP As String = Source.IndexOf(EndKey, StringComparison.OrdinalIgnoreCase)
    ' 應該修改為以下寫法 =>
    StartP = StartP + StartKey.Length
    Dim EndP As String = Source.IndexOf(EndKey, StartP, StringComparison.OrdinalIgnoreCase)    


另外 我也針對 StringComparison 做一些測試 
然後以一個 20KB 的 html 去抓出 <!--Content E--> 的位置
測試結果如下 (StartP 是 <!--Content S--> 後的起始位置)


0.0005085 No StartP
0.0002082 with StartP
0.0000157 StringComparison.Ordinal with StartP
0.0002768 StringComparison.OrdinalIgnoreCase, No StartP
0.0001105 StringComparison.OrdinalIgnoreCase with StartP
0.0002116 StringComparison.CurrentCulture with StartP
0.0002085 StringComparison.CurrentCultureIgnoreCase with StartP


結論: 
1. IndexOf 預設是以 StringComparison.CurrentCulture 方式尋找字串
2. 對於大塊字串,請盡量用 StartP 去找結束標籤位置,這樣速度會快很多,因為少爬了一段文字,此範例是差了2.5倍
3. 對於大塊字串,除非大小寫都要找,不然盡量用 StringComparison.Ordinal 來尋找字串,速度差了7~8倍

微軟對於.NET字串處理 有一篇建議文章,請大家拜讀一下
http://msdn.microsoft.com/zh-tw/library/vstudio/dd465121(v=vs.100).aspx
More...
darren, 2014/1/14 下午 03:18:14
Global 網站使用 CultureInfo 物件
製作 Global 網站時,由於User來自世界各地
而各地對於時間格式以及貨幣,數字顯示方式都有所不同
這時就需要 .NET Globalization -> CultureInfo 來處理這個問題
CultureInfo 是基於 Language Code 來的
而 user 的 Language Code 基本上瀏覽器會放在 Request Header 送到Server
(ex. Accept-Language: zh-TW,zh;q=0.8,en-US;q=0.6,en;q=0.4)

        Dim d As Date = Now
        Dim n As Decimal = 86400.99
        Dim Cultures() As String = {"zh-TW", "pt-BR", "pt-PT", "en-US", "en-GB", "fr-FR", "de-DE", "es-ES", "ja-JP", "zh-CN", "ko-KR", "en-IN"}
        For i As Integer = 0 To Cultures.GetUpperBound(0)
            Dim c As New Globalization.CultureInfo(Cultures(i))
            Response.Write(Cultures(i) & "<br/>" & d.ToString("D", c) & " <br/>" & d.ToString("d", c) & "<br/>" & n.ToString("C", c))
            Response.Write("<hr/>")
        Next


結果如下:

zh-TW
2013年12月25日
2013/12/25
NT$86,400.99

pt-BR
quarta-feira, 25 de dezembro de 2013
25/12/2013
R$ 86.400,99

pt-PT
quarta-feira, 25 de Dezembro de 2013
25-12-2013
86.400,99 €

en-US
Wednesday, December 25, 2013
12/25/2013
$86,400.99

en-GB
25 December 2013
25/12/2013
£86,400.99

fr-FR
mercredi 25 décembre 2013
25/12/2013
86 400,99 €

de-DE
Mittwoch, 25. Dezember 2013
25.12.2013
86.400,99 €

es-ES
miércoles, 25 de diciembre de 2013
25/12/2013
86.400,99 €

ja-JP
2013年12月25日
2013/12/25
¥86,401

zh-CN
2013年12月25日
2013/12/25
¥86,400.99

ko-KR
2013년 12월 25일 수요일
2013-12-25
₩86,401

en-IN
25 December 2013
25-12-2013
₹ 86,400.99
More...
darren, 2013/12/26 下午 04:04:39
善用 Request.Cookies.Set After Respnse.Cookies.Add
ASP.NET程式開發時,有時候會寫資料到cookies
這時我們會用 Response.Cookies.Add 寫入
但是大家都會忽略到一種情況,如果後面程式也會使用到該cookies時
Request.Cookies 會抓不到剛設定的cookies
這時就要 Request.Cookies.Set 來設定 Request 值

錯誤示範:
Page_Load --> Response.Cookies.Add a Cookie named "test"
Page_PreRender --> Request.Cookies("test") --> Nothing 

正確示範(同時寫兩行):
Page_Load --> Response.Cookies.Add a Cookie named "test"
              Request.Cookies.Set a Cookie named "test" 
Page_PreRender --> Request.Cookies("test") --> Got it!

 
More...
darren, 2013/11/4 下午 06:37:03
DataTable 的 Rows.Find 效能較佳
因為 SHOPUNT 的線上產品有兩千多筆,然後網站有非常頻繁的查詢
例如檢查產品是否停賣

原本的寫法是用以下方法尋找

DT.Select("Id=" & ProductId) 


後來改寫 DataTable 加上 PrimaryKey

'寫入Cache前先設定好
DT.PrimaryKey = New DataColumn() {obj.Columns("Id")} 
Dim row As DataRow = DT.Rows.Find(ProductId)


共1085筆 找出其中一筆 
Select方法  - 00:00:00.0000559
Rows.Find -   00:00:00.0000064

兩者速度差了約10倍
 
More...
darren, 2013/9/5 上午 11:58:39
IIS 7 & 7.5 的動態壓縮設定
關於IIS 7 (7.5)設定動態壓縮,如何啟用這裡就不用多敘述
只是他如何判別哪些動態內容要壓縮,哪些內容不壓縮呢?
這些設定其實在 applicationHost.config 設定
位置: C:\Windows\System32\inetsrv\Config\applicationHost.config
區段:
        
<httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files">
    <scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" />
    <staticTypes>
        <add mimeType="text/*" enabled="true" />
        <add mimeType="message/*" enabled="true" />
        <add mimeType="application/x-javascript" enabled="true" />
        <add mimeType="application/atom+xml" enabled="true" />
        <add mimeType="application/xaml+xml" enabled="true" />
        <add mimeType="application/json" enabled="true" />
        <add mimeType="*/*" enabled="false" />
    </staticTypes>
    <dynamicTypes>
        <add mimeType="text/*" enabled="true" />
        <add mimeType="message/*" enabled="true" />
        <add mimeType="application/x-javascript" enabled="true" />
        <add mimeType="application/json" enabled="true" />
        <add mimeType="*/*" enabled="false" />
    </dynamicTypes>
</httpCompression>

其中,<add mimeType="application/json" enabled="true" /> 是我自己加上的,不是系統預設的
當然,決定哪些靜態檔要壓縮也在 <staticTypes> 這裡設定
IIS 的 mime對應最好也加上 *.json -> application/json
 
More...
darren, 2013/8/8 下午 01:59:01
SessionState 效能影響問題
昨天Peter提到同一個 Session 只能一次 Request一個 Page
發現這篇文章有描述 http://blog.darkthread.net/post-2011-08-27-aspx-session-lock.aspx
主要是為了保持Session Data一致性 所以要 Lock Session

所以網頁綁 SessionState 是會影像效能的,尤其使用 StateServer 或 SqlServer 方式影響更大
一般.aspx 預設是有的,所以 aspx 有個 EnableSessionState 可以處理是否綁 SessionState
True: 可 Read, Write
ReadOnly: 可 Read
False: 完全不綁定 Session
如果網頁完全用不到 Session,可以考慮把她關閉,效能會好一點,但要注意相關程式碼、元件是否有用到,不然會有Exception

另外 web handler (.ashx) 預設是不綁 Session 的,對於單純的程式處理(例如 Ajax),建議用.ashx
但是在某些狀況下,.ashx 可能需要用到 Session
這時就要import( or using) Web.SessionState, 然後 Class 實作 IRequiresSessionState Interface
就OK啦
More...
darren, 2013/7/12 上午 10:24:57
Response.Redirect throws an “Thread was being aborted”
當我們用 try catch 去包程式時,要注意不要讓程序結束跳出
這樣會引發 Thread was being aborted 錯誤
例如 try catch 不要做 Respnse.Redirect 動作
請參考此文章
 
More...
darren, 2013/3/15 上午 11:21:31
程式技巧: 以字串陣列來取代拼字串
最近看到一些 javascript 範例 覺得這樣不錯的
就是用 array push, join 方式來拼字串

    var Data = [{"key": "key5", "value": "value5"}, {"key": "key4", "value": "value4"}, {"key": "key3", "value": "value3"}];
    var html = [];
    html.push('<select name="test">');
    for (var i = 0; i < Data.length; i++) {
        html.push('<option value="' + Data[i]["key"] + '">',
            Data[i]["value"],
            "</option>");
    }
    html.push('</select>');
    return html.join('');


同樣的方式 .net 也可以這樣做

        List<string> listOfString = new List<string>();
        for (int i = 0; i < 10; i++)
        {
            listOfString.Add(i.ToString());
        }
        string strResult = string.Join(", ", listOfString.ToArray());


用這種方式也省的判別最後一筆要不要加上分隔符號
More...
darren, 2012/10/17 下午 04:09:20
|< 123 >|
頁數 2 / 3 上一頁 下一頁
~ Uwinfo ~