Asp.Net 與 tortoisesvn

早上去看tortoisesvn的時候,發現已經釋出新版,看了一下新版的發行公告,發現新版的tortoisesvn已經解決討厭的 asp.net 問題了.

The “_svn” hack is now officially supported: since some versions of ASP.NET don’t allow directories beginning with dot (e.g., “.svn”, the standard Subversion working copy administrative directory), TortoiseSVN now treats the environment variable SVN_ASP_DOT_NET_HACK specially. If this variable is set (to any value), it will use “_svn” instead of “.svn”. Note that once the environment variable is set, working copies with standard “.svn” directories will stop working, and will need to be re-checked-out to get “_svn” instead.

簡單的說,只要設置環境變數:SVN_ASP_DOT_NET_HACK 就行了.
不知道 subversion 是不是也是一樣的設置方法.

我的生命靈數

在朋友的 blog 上看到的:我的生命靈數
看到了,就要作一作.

靈  數: 6
這個數字顯示
好好利用這個階段調整工作目標,改善自己不良的習慣,改進溝通技巧和人際關係,將負面的觀念引導到正面,並且學習一種適合自己的身心療法,記得要心存大愛,多多耕種你的善念和善行,為進入下一階段的幸運作好準備!
這個階段對於感情的穩定很有幫助,尤其新的戀愛會很好,是充滿浪漫的時段。另外,分享會使得你更成熟,更加富有,因為這會讓你四散的能量再度聚合起來,發揮出力量,讓你的內心告別貧乏,逐漸豐美,記得好好和身邊的朋友一起分享美好的希望與成果喔!

相當不錯的參考.

mono 與 SELinux

重灌 server 並啟用 SELinux 以後,發現 asp.net 應用程式無法啟動.
原本不想碰 SELinux 的,不得已,出來混的早晚都要還,只好硬著頭皮去K.
經過研讀文件之後,大致上對 SELinux 有一定的瞭解.
SELinux 本身純粹是作安全性的加強,所以不管是 user, file, directory, socket, process…等等的,都另外有了 security context,作為安全性的第二道防線.
當系統要存取這些資源的時候,首先會使用原有的 unix permission 去作檢查,接著 SELinux 會再依照 security context 作第二道檢查,當檢查沒問題之後,才會允許存取.
SELinux 裡面有所謂的 identity, domain, type, security context, target context 等等物件…
大致上來說, identity 決定身份, domain 決定 process 能幹麼, type 決定 process 以外的物件可以幹麼, security context, target context 則是 identity + domain + type 的組合. policy 則用來定義 security context, target context 可以存取哪些物件. (這些組合,真的很讓人頭暈.)
存取的指令也蠻多的:

  • 要看檔案目錄的 security context, 可以加上 -Z (ls -Z)
  • 要看process的 security context, 也可以用 -Z (ps axZ)
  • 要看自己的security context,可以用 id
  • 要改security context, 可以用 chcon
  • 要 reset security context, 可以用 restorecon

整個研讀完之後,發現應該是 policy 問題.
今天下午用Google去找到 v14, i08: Tuning Your SELinux Policy with Audit2allow” href=”http://www.samag.com/documents/s=9820/sam0508a/0508a.htm”>這篇文章,發現有這麼個工具 – audit2allow,他是在 policycoreutils 套件裡面的指令,可以根據 warning message 產生 policy,省掉不少編寫的麻煩.
為了要能重新編譯 policy, 你需要安裝 selinux-policy-targeted-sources 這個套件

yum install selinux-policy-targeted-sources

再使用 audit2allow 這個指令,從 dmesg 裡面分析 warning, 並將產生以後的 policy 寫入到 mono.policy 檔案中.

audit2allow -d -o mono.policy

接著把 mono.policy 更名為 local.te, 放到 /etc/selinux/targeted/src/policy/domains/misc/ .
放完之後,切換到 /etc/selinux/targeted/src/policy
強制 selinux 重新編譯 policy

make load

最後重新啟動我的 Apache server,就大功告成了.
參考資料:

ThreadAbortException

原來呼叫 Response.End() 就會丟出 ThreadAbortException.
害我以為是我程序出現錯誤了呢…
Google 幫忙一下,原來也有人碰到同樣情況:
Impersonation Failure : ASP.NET – ThreadAbortException
其實還不只是 Response.End(), Server.Transfer() 與 Response.Redirect() 也有機會發生此狀況,因為他們內部也呼叫了 Response.End().
比較正確的作法應該還是先呼叫

Response.Flush();
Response.Close();

會比較好些.
這是那篇文章所提供的參考資料:

log4net

在 .Net/mono 程序裡面使用 log4net,是極為簡單的事情.
首先到 log4net官方網站下載.
解開以後,到 bin 資料夾下,找適合你用的 assembly file. (p.s. 其實也不用特別找, .Net 與 mono 是通用的, .Net compact framework 與 sccli 我就沒試過了)
接著,視你自己專案的類型,該引用的就引用 (Visual Studio.Net/MonoDevelop/SharpDevelop),該改 Nant build file / Makefile 的就改.
步驟一:
使用 log4net 的第一步,是在你程序一開始的地方,去解析 log4net 的 configuration.

log4net.Config.XmlConfigurator.Configure();

一般性的 Windows form 程序通常是放在 Main 的一開始,而 asp.net 程序通常則是在 global.asax (codebehind 的話就是 global.asax.cs) 的 Application_Start 事件.
步驟二:
接著在你想要進行 log 的類別宣告這一個屬性.

protected static readonly ILog log = LogManager.GetLogger(typeof( your_class_name ));

要當成一般變數來用也行

ILog log = LogManager.GetLogger(typeof( your_class_name ));

步驟三:
最後是在你想要 log 的地方,放置這麼一行

log.Info( “your message here.” );

大功告成!!
就這麼簡單.
而 ILog 不只 Info() method 可以操作,還可以有 Debug(), Error(), Fatal(), Warn() 這幾個 method 可用,他們各代表了不同的層級.
層級的區分大致是這樣: Debug < Info < Warn < Error < Fatal
換句話說,當你 Configuration 裡的層級設定為 Debug 的時候,只要你有調用 ILog 的任何一個 method 來 log, 這些訊息都會出現在 log 裡面.
當你 Configuration 裡的層級設為 Warn 的時候,你有調用 Warn(), Error(), Fatal() 這三個 method 來 log 的地方,這些訊息都會出現在 log 裡面.
再來就是 Configuration.
Windows form 的 configuration 檔案通常名稱是 xxx.exe.config, asp.net 的 configuration 檔案則是 web.config
這裡主要放置兩個部份:

  • configSection:

    <configSections>
    <section name=”log4net” type=”log4net.Config.Log4NetConfigurationSectionHandler,log4net” />
    </configSections>

    p.s.這裡我有一個慘痛的教訓,查了好久,結果發現是打錯字, “log4net.Config” 我打成 “log4net.config”,一度我還懷疑是 configuration file 問題,還跑去 trace log4net 的程式 =_=”, 如果你確定你都設對了,該設的也都設定了,不妨利用 LogManager.GetRepository 取得 ILoggerRepository,去看 Configured 屬性,如果是 false,表示沒設定到,可以試著檢查大小寫看看.

  • log4net, 這邊請參考 log4net Config Examples 會比較快一點.

參考資料:

2005年回顧

  • PMP順利出貨
  • 應M客戶要求,加上像 iPod 一樣的 ID3 tag 導引功能.還有 audio resume 功能(基本上是抄原有的 video resume)
  • 去了大陸崑山一趟,沒玩甚麼,因為沒有帶旅遊導覽.
  • 把 UML 看過一遍
  • 把結構化系統分析看過一遍
  • 開始去中和的國立中央圖書館台灣分館借書
  • 開始玩仙境傳說 (http://blog.xuite.net/x991275c/ThinkingRo/)
  • 開始離職信收集的 blog (http://farewellcollection.blogspot.com/)
  • 第一次趕流行喝薄酒來
  • 重感冒兩次,中度感冒一次
  • 開始認真寫 asp.net, 把 rss 時刻表重寫了兩次,正在重寫第三次中…
  • 去韓國
  • 喝掛一次,沒當場醉倒,隔天宿醉,痛苦了一天.
  • 恢復閱讀的習慣