標籤

ASP.NET MVC (29) Visual C# (15) JQuery (10) Plugins (8) JQuery Plugins (6) JavaScript (6) MySQL (5) CSS (4) LinQ (4) Mac OS (4) CentOS (3) Design Pattern (3) Entity Framework (3) IIS (3) Python (3) Windows (3) php (3) Docker (2) LAMP (2) SQL Server (2) WCF (2) .NET (1) .NET Core (1) AWS (1) Browser (1) GIS (1) IE (1) Internet Security (1) Linux (1) Platform (1) React (1) SEO (1) Testing (1) VMware (1) Windows 7 (1) cookie (1) curl (1) laravel (1) phpBB (1) session (1) 中古屋 (1) 透天 (1) 閒言閒語 (1) 面試 (1) 鳥松 (1)

2013年10月18日 星期五

[Visual C#][Design Pattern] C#實作執行緒安全(thread-safe)的Singleton類別


Singleton是撰寫程式時常用到的一個設計模式,例如需要實作某個單一控管的容器(連接池是一個例子),同時也需要考慮Singleton類別的執行緒安全,我們必須保證不會同時有兩個以上的物件被實體化(new instance)。

以下是一個Singleton類別的範例,此範例使用雙重判斷(double-check)的手法來避免兩個以上的物件被實體化:

public sealed class Singleton

{
   private static volatile Singleton instance;
   private static object syncRoot = new Object();

   private Singleton() {}
   public static Singleton Instance
   {
      get
      {
         if (instance == null)
         {
            lock (syncRoot)
            {
               if (instance == null)
                  instance = new Singleton();
            }
         }
         return instance;
      }
   }
}



[Reference]:

Implementing Singleton in C#

Thread Safe C# Singleton Pattern

2013年5月15日 星期三

[ASP.NET MVC][IIS]在應用程式層級之外使用註冊為 allowDefinition='MachineToApplication' 的區段發生錯誤。錯誤的原因可能是虛擬目錄尚未在 IIS 中設定為應用程式


針對網站做發行時發生下列錯誤訊息導致無法發行:

在應用程式層級之外使用註冊為 allowDefinition='MachineToApplication' 的區段發生錯誤。錯誤的原因可能是虛擬目錄尚未在 IIS 中設定為應用程式

網路上找了一下,大致原因是存在了重複的WebConfig檔案,下意識把整個obj目錄砍了再發行一次就沒問題了,詳細原因沒研究。


保哥部落格有相關資訊:

ASP.NET MVC 建置部署套件後無法 MvcBuildViews 的解法

Reference:

Asp.net MVC 建置發行時出現錯誤訊息:錯誤的原因可能是虛擬目錄尚未在 IIS 中設定為應用程式。






















2013年5月11日 星期六

[Internet Security] DNS 放大攻擊 DNS Amplification Attacks

[原理] :
透過使用IP對DNS Server反查所有有用到這個Domain的SubDomain清單,可能送出查詢只有1K,但是DNS Server回復訊息可能是100K或以上,造成放大攻擊(1:100)使受害的DNS Server癱瘓,造成其他使用者無法正常瀏覽該網站。屬於DDOS攻擊的一種。

[解決方案]:
DNS Server上設置每秒最多查詢量的限制。

[Reference]:




DNS 放大攻擊(DNS Amplification Attacks)

2012年12月19日 星期三

[VMware] 使用Vmware安裝Centos複製虛擬機後eth0網卡發生問題

複製虛擬機後,由於CentOS會記住Mac Address,但是重新啟動後會配發一個新的Mac Address 並且新增一個eth1的網卡。

解決方式為將失效的eth0的Mac Address改為新的Mac Address,新的Mac Address在路徑:
[/etc/udev/rules.d/70-persistent-net.rules]中


# This file was automatically generated by the /lib/udev/write_net_rules
# program, run by the persistent-net-generator.rules rules file.
#
# You can modify it, as long as you keep each rule on a single
# line, and change only the value of the NAME= key.

# PCI device 0x8086:0x100f (e1000)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:d4:99:d3", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"




只要將eth0的Mac Address改為 00:0c:29:d4:99:d3

並且重新啟動網路    >service network restart

2012年9月4日 星期二

[Windows] MSDN開放下載 Windows Server 2012正式版

MSDN開放下載 Windows Server 2012正式版囉 總共有五個版本
有訂閱的人可以下載來玩玩看~


Windows Server 2012 Standard
零售
您已索取 0 個金鑰 (共 ? 個金鑰)
Windows Server 2012 Datacenter
零售
您已索取 0 個金鑰 (共 ? 個金鑰)
Windows Server 2012 Storage Server Workgroup
零售
您已索取 0 個金鑰 (共 ? 個金鑰)
Windows Server 2012 Storage Server Standard
零售
您已索取 0 個金鑰 (共 ? 個金鑰) 
Windows Server 2012 Foundation
零售
您已索取 0 個金鑰 (共 ? 個金鑰) 


WIKI 有版本差異比較表,上面的取得金鑰連結無作用,請登入自己的MSDN帳戶下載。

2011年11月10日 星期四

[JavaScript] function statement requires a name

function statement requires a name
---

在ASP MVC中使用 Ajax:
@Ajax.ActionLink("刪除", "Delete", new { id = item.Id },
new AjaxOptions()
{
HttpMethod= "Delete",
Confirm="你確定要刪除嗎?",
OnSuccess = "function() { alert('hello'); }"
})

改為下面這樣就好了:
OnSuccess = "(function() { alert('hello'); })()"

Reference :

Javascript anonymous functions in Firefox 7

2011年11月9日 星期三

伺服器 '' 上的 MSDTC 無法使用。

昨天懶得重開電腦,就直接休眠了,結果今天早上run程式的時候就發生這個錯誤:

'/' 應用程式中發生伺服器錯誤。

伺服器 'XX\SQL2008R2' 上的 MSDTC 無法使用。

描述: 在執行目前 Web 要求的過程中發生未處理的例外情形。請檢閱堆疊追蹤以取得錯誤的詳細資訊,以及在程式碼中產生的位置。

例外詳細資訊: System.Data.SqlClient.SqlException: 伺服器 'XX\SQL2008R2' 上的 MSDTC 無法使用。

原始程式錯誤: ...

---
後來發現是 Distributed Transaction Coordinator (MSDTC) 這個服務停止了,所以只要有包含交易(Transaction)的區段都會出錯,把服務重新啟動一次就好囉。