<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>DucDigital</title>
	<atom:link href="http://www.ducdigital.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ducdigital.com</link>
	<description>for ( $girl = 1; $girl &#60; $required; $girl++ ) { echo "I love DucDigital"; }</description>
	<lastBuildDate>Wed, 03 Mar 2010 10:13:39 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Open selling Vbulletin 3 4x and VbSeo license</title>
		<link>http://www.ducdigital.com/2010/03/03/open-selling-vbulletin-3-4x-and-vbseo-license/</link>
		<comments>http://www.ducdigital.com/2010/03/03/open-selling-vbulletin-3-4x-and-vbseo-license/#comments</comments>
		<pubDate>Wed, 03 Mar 2010 10:13:39 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[license]]></category>
		<category><![CDATA[owned]]></category>
		<category><![CDATA[vbseo]]></category>
		<category><![CDATA[vbulletin]]></category>

		<guid isPermaLink="false">http://www.ducdigital.com/?p=229</guid>
		<description><![CDATA[hi everyone, just recently I start open sale for Vbulletin 3 and 4x owned license. These license are legit from their respective owner and can be transfer to your name. 
Currently, my price is 
VbSeo: 59.99$
vBulletin 4.0 Forum Classic owned license : $79.99
vBulletin 4.0 Publishing Suite owned license : $119.99
vBulletin License 3.x Owned license: 30$
If [...]]]></description>
			<content:encoded><![CDATA[<p>hi everyone, just recently I start open sale for Vbulletin 3 and 4x owned license. These license are legit from their respective owner and can be transfer to your name. </p>
<p>Currently, my price is </p>
<blockquote><p>VbSeo: 59.99$<br />
vBulletin 4.0 Forum Classic owned license : $79.99<br />
vBulletin 4.0 Publishing Suite owned license : $119.99<br />
vBulletin License 3.x Owned license: 30$</p></blockquote>
<p>If anyone who interested please email me to Duc [ at] ducdigital.com for more details. </p>
<p>We accept <strong>paypal </strong>and <strong>alertpay</strong>. </p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.ducdigital.com%2F2010%2F03%2F03%2Fopen-selling-vbulletin-3-4x-and-vbseo-license%2F&amp;linkname=Open%20selling%20Vbulletin%203%204x%20and%20VbSeo%20license"><img src="http://www.ducdigital.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.ducdigital.com/2010/03/03/open-selling-vbulletin-3-4x-and-vbseo-license/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Automatic change DNS for Facebook</title>
		<link>http://www.ducdigital.com/2010/02/16/facebook-dns-in-vietnam/</link>
		<comments>http://www.ducdigital.com/2010/02/16/facebook-dns-in-vietnam/#comments</comments>
		<pubDate>Tue, 16 Feb 2010 14:51:45 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[autoit]]></category>
		<category><![CDATA[china]]></category>
		<category><![CDATA[dns]]></category>
		<category><![CDATA[facebook]]></category>
		<category><![CDATA[vietnam]]></category>

		<guid isPermaLink="false">http://www.ducdigital.com/?p=226</guid>
		<description><![CDATA[For the last few month, the Vietnamese Government has issue a ban on Facebook, just like in China. My friend has take his little time to write a small bot to change DNS between openDNS, Google Public DNS  and DHCP DNS. Using this program you can switch between those 3 type DNS fast. Simply [...]]]></description>
			<content:encoded><![CDATA[<p>For the last few month, the Vietnamese Government has issue a ban on Facebook, just like in China. My friend has take his little time to write a small bot to change DNS between <a href="http://www.opendns.com/">openDNS</a>, <a href="http://code.google.com/speed/public-dns/">Google Public DNS </a> and DHCP DNS. Using this program you can switch between those 3 type DNS fast. Simply just download, run it as Administrator (if you are using Vista / Win 7) and it do the job for you. </p>
<p>Now you can surf web safer without restriction. and better yet, I recommend you buy a SSH and use it as Sock5 for safer web browse in some location.</p>
<hr />
<p>Một vài tháng trước Đảng ta đã chặn facebook và cho facebook vào 1 trong những trang "Có Nội Dung Chống Phá Nhà Nước Việt Nam". Thực sự sự việc có nhiều âm mưu đằng sau đó, như là việc sau khi nhà nước xóa sổ facebook thì zing me lại nổi lên với kiểu mạng xã hội copy/ăn theo/ăn cắp ý tưởng. Một phần khác cũng là do việc có nhiều nhóm chống phá nhà nước VN trụ tại facebook.</p>
<p>Nhưng facebook đã trở thành phương tiện liên lạc của nhiều người VN ở trong nước lẫn những du học sinh, người Việt nam ở nước ngoài, phải gọi là 1 cổng thông tin giữa VN và bạn bè trên tòan thế giới. Việc chặn lại facebook đã gây vấn đề bức xúc cho người dân VN ta.</p>
<p>Đây là chương trình tự động đổi DNS do một người bạn của Đức viết để cỏ thể tự động chuyển đổi giữa Open DNS, Google Public DNS hoặc DNS gốc của mạng bạn. Những ai ít có kinh nghiệm máy tính có thể dùng chương trình này để đổi DNS của mình một cách gọn gàng nhất.</p>
<p>Lưu ý: đối với ngưoiừ nào sử dụng Win 7 hoặc Vista, bạn phải chạy với chế độ "Run as Administrator".<br />
-> Chương trình không có gì ngoải việc chạy ipconfig để đổi lại DNS. Chương trình đựơc viết = AutoIt. Đựơc quét virus và khẳng định kô có mã bẩn.</p>
<p><strong>Source and Download: <a href="http://ducdigital.com/dns">http://ducdigital.com/dns</a></strong></p>
<p>Source code:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#NoTrayIcon
</span><span style="color: #666666; font-style: italic;">#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
</span><span style="color: #666666; font-style: italic;">#AutoIt3Wrapper_Version=Beta
</span><span style="color: #666666; font-style: italic;">#AutoIt3Wrapper_icon=facebook.ico
</span><span style="color: #666666; font-style: italic;">#AutoIt3Wrapper_Compression=4
</span><span style="color: #666666; font-style: italic;">#AutoIt3Wrapper_Res_Comment=Chương trình thay đổi DNS Sever của máy thành các loại DNS Sever khác
</span><span style="color: #666666; font-style: italic;">#AutoIt3Wrapper_Res_Description=DNS Sever Option
</span><span style="color: #666666; font-style: italic;">#AutoIt3Wrapper_Res_Fileversion=2.0.1.0
</span><span style="color: #666666; font-style: italic;">#AutoIt3Wrapper_Res_LegalCopyright=Hoàng Ðức Nghiêm (HĐN)
</span><span style="color: #666666; font-style: italic;">#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
</span>
Local <span style="color: #000088;">$Temp</span> <span style="color: #339933;">=</span> <span style="color: #339933;">@</span>TempDir<span style="color: #339933;">&amp;</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\N</span>etworkConnection.tmp&quot;</span>
&nbsp;
GUICreate<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">100</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">116</span><span style="color: #339933;">,-</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,-</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span><span style="color: #208080;">0x00400000</span><span style="color: #009900;">&#41;</span>
<span style="color: #000088;">$ISP</span> <span style="color: #339933;">=</span> GUICtrlCreateButton<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ISP DNS Sever&quot;</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">117</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">30</span><span style="color: #009900;">&#41;</span>
<span style="color: #000088;">$Open</span> <span style="color: #339933;">=</span> GUICtrlCreateButton<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Open DNS Sever&quot;</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">30</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">117</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">30</span><span style="color: #009900;">&#41;</span>
<span style="color: #000088;">$Google</span> <span style="color: #339933;">=</span> GUICtrlCreateButton<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Google Public DNS&quot;</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">60</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">117</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">30</span><span style="color: #009900;">&#41;</span>
&nbsp;
GUISetState<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
ToolTip<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Xin vui lòng chọn một loại DNS Sever để thay đổi&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;DNS Sever (Unknow DNS)&quot;</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span>
&nbsp;
<span style="color: #b1b100;">While</span> <span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span>
	<span style="color: #000088;">$Msg</span> <span style="color: #339933;">=</span> GUIGetMsg<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	Select
		<span style="color: #b1b100;">Case</span> <span style="color: #000088;">$Msg</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$ISP</span>
			<span style="color: #000088;">$DNS</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;ISP DNS&quot;</span>
			<span style="color: #000088;">$DNS1</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;dhcp&quot;</span>
			<span style="color: #000088;">$DNS2</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;dhcp&quot;</span>
			ExitLoop
		<span style="color: #b1b100;">Case</span> <span style="color: #000088;">$Msg</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$Open</span>
			<span style="color: #000088;">$DNS</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Open DNS&quot;</span>
			<span style="color: #000088;">$DNS1</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;208.67.222.222&quot;</span>
			<span style="color: #000088;">$DNS2</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;208.67.220.220&quot;</span>
			ExitLoop
		<span style="color: #b1b100;">Case</span> <span style="color: #000088;">$Msg</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$Google</span>
			<span style="color: #000088;">$DNS</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Google Public DNS&quot;</span>
			<span style="color: #000088;">$DNS1</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;8.8.8.8&quot;</span>
			<span style="color: #000088;">$DNS2</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;8.8.4.4&quot;</span>
			ExitLoop
	EndSelect
WEnd
&nbsp;
GUIDelete<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
ToolTip<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Tạo File đệm và lấy thông tin kết nối&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;DNS Sever (&quot;</span><span style="color: #339933;">&amp;</span><span style="color: #000088;">$DNS</span><span style="color: #339933;">&amp;</span><span style="color: #0000ff;">&quot;)&quot;</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span>
_RunDOS<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ipconfig &gt; &quot;</span><span style="color: #339933;">&amp;</span><span style="color: #000088;">$Temp</span><span style="color: #009900;">&#41;</span>
&nbsp;
<span style="color: #000088;">$Connection</span> <span style="color: #339933;">=</span> FileReadLine<span style="color: #009900;">&#40;</span><span style="color: #000088;">$Temp</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span>
<span style="color: #000088;">$Connection</span> <span style="color: #339933;">=</span> StringTrimLeft<span style="color: #009900;">&#40;</span><span style="color: #000088;">$Connection</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">17</span><span style="color: #009900;">&#41;</span>
<span style="color: #000088;">$Connection</span> <span style="color: #339933;">=</span> StringTrimRight<span style="color: #009900;">&#40;</span><span style="color: #000088;">$Connection</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span>
FileDelete<span style="color: #009900;">&#40;</span><span style="color: #000088;">$Temp</span><span style="color: #009900;">&#41;</span>
&nbsp;
ToolTip<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Thay đổi thông số của DNS Sever&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;DNS Sever (&quot;</span><span style="color: #339933;">&amp;</span><span style="color: #000088;">$DNS</span><span style="color: #339933;">&amp;</span><span style="color: #0000ff;">&quot;)&quot;</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span>
_RunDOS<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ipconfig/flushdns'</span><span style="color: #009900;">&#41;</span>
_RunDOS<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'netsh interface ip set dns &quot;'</span><span style="color: #339933;">&amp;</span><span style="color: #000088;">$Connection</span><span style="color: #339933;">&amp;</span><span style="color: #0000ff;">'&quot; static '</span><span style="color: #339933;">&amp;</span><span style="color: #000088;">$DNS1</span><span style="color: #339933;">&amp;</span><span style="color: #0000ff;">' primary'</span><span style="color: #009900;">&#41;</span>
_RunDOS<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'netsh interface ip add dns &quot;'</span><span style="color: #339933;">&amp;</span><span style="color: #000088;">$Connection</span><span style="color: #339933;">&amp;</span><span style="color: #0000ff;">'&quot; '</span><span style="color: #339933;">&amp;</span><span style="color: #000088;">$DNS2</span><span style="color: #009900;">&#41;</span>
&nbsp;
ToolTip<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span>
MsgBox<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">64</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;Đã xong&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;Thay đổi DNS Sever thành công!&quot;</span><span style="color: #339933;">&amp;@</span>CRLF<span style="color: #339933;">&amp;</span><span style="color: #0000ff;">&quot;Chúc bạn vui vẻ...  *~(^.^)~*&quot;</span><span style="color: #009900;">&#41;</span>
&nbsp;
Func _RunDOS<span style="color: #009900;">&#40;</span><span style="color: #000088;">$sCommand</span><span style="color: #009900;">&#41;</span>
	Local <span style="color: #000088;">$nResult</span> <span style="color: #339933;">=</span> RunWait<span style="color: #009900;">&#40;</span><span style="color: #339933;">@</span>ComSpec <span style="color: #339933;">&amp;</span> <span style="color: #0000ff;">&quot; /C &quot;</span> <span style="color: #339933;">&amp;</span> <span style="color: #000088;">$sCommand</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">,</span> <span style="color: #339933;">@</span>SW_HIDE<span style="color: #009900;">&#41;</span>
	<span style="color: #b1b100;">Return</span> SetError<span style="color: #009900;">&#40;</span><span style="color: #339933;">@</span>error<span style="color: #339933;">,</span> <span style="color: #339933;">@</span>extended<span style="color: #339933;">,</span> <span style="color: #000088;">$nResult</span><span style="color: #009900;">&#41;</span>
EndFunc</pre></td></tr></table></div>

<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.ducdigital.com%2F2010%2F02%2F16%2Ffacebook-dns-in-vietnam%2F&amp;linkname=Automatic%20change%20DNS%20for%20Facebook"><img src="http://www.ducdigital.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.ducdigital.com/2010/02/16/facebook-dns-in-vietnam/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>New chrome!</title>
		<link>http://www.ducdigital.com/2010/02/01/new-chrome/</link>
		<comments>http://www.ducdigital.com/2010/02/01/new-chrome/#comments</comments>
		<pubDate>Mon, 01 Feb 2010 03:59:46 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[browser]]></category>
		<category><![CDATA[Chrome]]></category>
		<category><![CDATA[google]]></category>

		<guid isPermaLink="false">http://www.ducdigital.com/?p=224</guid>
		<description><![CDATA[Yes, finally Google Chrome has updated accordingly to the lastest stable of Chrominium. The new version of Chrome feature plugins extension and import bookmark to google account (I really looking forward for this feature) 
There are some interesting plugin out there for chrome, check out: https://chrome.google.com/extensions/
]]></description>
			<content:encoded><![CDATA[<p>Yes, finally Google Chrome has updated accordingly to the lastest stable of Chrominium. The new version of Chrome feature plugins extension and import bookmark to google account (I really looking forward for this feature) </p>
<p>There are some interesting plugin out there for chrome, check out: <a href="https://chrome.google.com/extensions/">https://chrome.google.com/extensions/</a></p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.ducdigital.com%2F2010%2F02%2F01%2Fnew-chrome%2F&amp;linkname=New%20chrome%21"><img src="http://www.ducdigital.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.ducdigital.com/2010/02/01/new-chrome/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Memcached and Asp.net mvc</title>
		<link>http://www.ducdigital.com/2010/01/23/memcached-and-asp-net-mvc/</link>
		<comments>http://www.ducdigital.com/2010/01/23/memcached-and-asp-net-mvc/#comments</comments>
		<pubDate>Fri, 22 Jan 2010 16:48:27 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Asp.net MVC]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[asp]]></category>
		<category><![CDATA[asp.net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[cache]]></category>
		<category><![CDATA[csharp]]></category>
		<category><![CDATA[enyim memcached]]></category>
		<category><![CDATA[linq]]></category>
		<category><![CDATA[linq to sql]]></category>
		<category><![CDATA[memcache]]></category>
		<category><![CDATA[memcached]]></category>
		<category><![CDATA[MemcachedProviders]]></category>
		<category><![CDATA[mvc]]></category>

		<guid isPermaLink="false">http://www.ducdigital.com/?p=220</guid>
		<description><![CDATA[Today I was hanging around on Google and found a lot of useful stuff about Memcached and .net. Currently, I am using System.Web.Cache to cache objects for my webpage stuff. It's good, but not enough for scalable since it's often remove my object when run on low memory.  So I go on with Memcached [...]]]></description>
			<content:encoded><![CDATA[<p>Today I was hanging around on Google and found a lot of useful stuff about Memcached and .net. Currently, I am using System.Web.Cache to cache objects for my webpage stuff. It's good, but not enough for scalable since it's often remove my object when run on low memory.  So I go on with Memcached instead. I found a lot of library which could help us develop faster. Here are some library/solution that I found:</p>
<p><a href="http://ayende.com/Blog/archive/2008/06/06/Scratching-an-itch-NMemcached.aspx">http://ayende.com/Blog/archive/2008/06/06/Scratching-an-itch-NMemcached.aspx</a><br />
<a href="http://www.codeproject.com/KB/aspnet/memcached_aspnet.aspx">http://www.codeproject.com/KB/aspnet/memcached_aspnet.aspx</a><br />
<a href="http://maxi326.wordpress.com/2009/11/02/use-memcached-in-net-application-with-linq/">http://maxi326.wordpress.com/2009/11/02/use-memcached-in-net-application-with-linq/</a><br />
<a href="http://zvolkov.com/blog/post/2009/06/18/Using-MemCached-with-NHibernate.aspx">http://zvolkov.com/blog/post/2009/06/18/Using-MemCached-with-NHibernate.aspx</a><br />
<a href="http://latebound.blogspot.com/2008/10/using-memcached-from-c.html">http://latebound.blogspot.com/2008/10/using-memcached-from-c.html</a><br />
<a href="http://www.codeplex.com/memcachedproviders">http://www.codeplex.com/memcachedproviders</a><br />
<a href="http://code.google.com/p/beitmemcached/">http://code.google.com/p/beitmemcached/</a><br />
<a href="http://sourceforge.net/projects/memcacheddotnet/">http://sourceforge.net/projects/memcacheddotnet/</a><br />
<a href="http://www.codeplex.com/EnyimMemcached/">http://www.codeplex.com/EnyimMemcached/</a><br />
and the list go on...</p>
<p>What is MemCached? To put this in simple term, it's a cache store / hash table, where you can store almost everything, like objects, on it. Basically, it's very useful since there are parts where you don't want to cache your whole webpage but you just want to cache your object which you finished process or pulled out from database. It can save you hundreds of ms query time, server loads, and process time, which is very very very useful.</p>
<p>There are some downside if you run Memcached on Windows, <del datetime="2010-01-22T12:46:56+00:00">the latest update for Memcached for windows that i can found is 1.2.5</del><a href="http://blog.northscale.com/northscale-blog/2009/12/memcached-144-windows-32bit-binary-now-available.html"> I found a latest version here: 1.4.4</a>, and the lates for linux is 1.4.4 (at the time I write this post). There are some solution for this problem. By using another computer/server installed as linux, you can solely run Memcached for cache purpose on multiple server. If you are not having more than 1 server, then just fall back to use System.Web.Cache since it's quite good for production already. You can also try out Velocity, which currently on it's CTP and I am not sure about whether Microsoft going to charge users for this.</p>
<p>I suggest you use MemCached Provider, it's the simplest to implement memcached in asp.net mvc, the following web.config instruction provided by MemCached Provider</p>
<p>Open Web.config file and add the following section to configSections tag</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;section</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;cacheProvider&quot;</span></span>
<span style="color: #009900;"><span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;MemcachedProviders.Cache.CacheProviderSection, MemcachedProviders&quot;</span></span>
<span style="color: #009900;"><span style="color: #000066;">allowDefinition</span>=<span style="color: #ff0000;">&quot;MachineToApplication&quot;</span> <span style="color: #000066;">restartOnExternalChanges</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;sectiongroup</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;enyim.com&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;section</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;memcached&quot;</span></span>
<span style="color: #009900;"><span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;Enyim.Caching.Configuration.MemcachedClientSection, Enyim.Caching&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/sectiongroup<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;section</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;log4net&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;log4net.Config.Log4NetConfigurationSectionHandler,log4net&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></div></div>

<p>Add the following section to configure Enyim’s client to point to Memcached servers</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;enyim</span> .com<span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;memcached<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servers<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #808080; font-style: italic;">&lt;!-- put your own server(s) here--&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">address</span>=<span style="color: #ff0000;">&quot;127.0.0.1&quot;</span> <span style="color: #000066;">port</span>=<span style="color: #ff0000;">&quot;11211&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servers<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;socketpool</span> <span style="color: #000066;">minPoolSize</span>=<span style="color: #ff0000;">&quot;10&quot;</span> <span style="color: #000066;">maxPoolSize</span>=<span style="color: #ff0000;">&quot;100&quot;</span></span>
<span style="color: #009900;"><span style="color: #000066;">connectionTimeout</span>=<span style="color: #ff0000;">&quot;00:00:10&quot;</span> <span style="color: #000066;">deadTimeout</span>=<span style="color: #ff0000;">&quot;00:02:00&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/memcached<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/enyim<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Add the following section to configure Memcached Cache Provider. keySuffix attribute allows for adding suffix to cache provider keys  in order to simulate namespaces.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;cacheprovider</span> <span style="color: #000066;">defaultProvider</span>=<span style="color: #ff0000;">&quot;MemcachedCacheProvider&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;providers<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;MemcachedCacheProvider&quot;</span></span>
<span style="color: #009900;"><span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;MemcachedProviders.Cache.MemcachedCacheProvider, MemcachedProviders&quot;</span></span>
<span style="color: #009900;"><span style="color: #000066;">keySuffix</span>=<span style="color: #ff0000;">&quot;_MySuffix_&quot;</span> <span style="color: #000066;">defaultExpireTime</span>=<span style="color: #ff0000;">&quot;2000&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/providers<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/cacheprovider<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p> Add following section to configure log4net</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;log4net<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #808080; font-style: italic;">&lt;!-- Define some output appenders --&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;appender</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;ConsoleAppender&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;log4net.Appender.ConsoleAppender&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;layout</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;log4net.Layout.PatternLayout&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;conversionpattern</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;%date [%thread] %-5level %logger [%property{NDC}]</span>
<span style="color: #009900;">- %message%newline&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/layout<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/appender<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #808080; font-style: italic;">&lt;!--&lt;threshold value=&quot;OFF&quot; /&gt;--&gt;</span>
<span style="color: #808080; font-style: italic;">&lt;!-- Setup the root category, add the appenders and set the default priority --&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;root<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;priority</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;WARN&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;appender</span> -ref <span style="color: #000066;">ref</span>=<span style="color: #ff0000;">&quot;ConsoleAppender&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;filter</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;log4net.Filter.LevelRangeFilter&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;levelmin</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;WARN&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;levelmax</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;FATAL&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/filter<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/appender<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/root<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/log4net<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Provided you include all the reference libraries, for example, this is my category controller, which will cache the object if it's not existed in the MemCached's memory.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;">        <span style="color: #0600FF;">public</span> ActionResult Category<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            var returnObj <span style="color: #008000;">=</span> DistCache.<span style="color: #0000FF;">Get</span><span style="color: #008000;">&lt;</span>list <span style="color: #008000;">&lt;</span>CategoryObject<span style="color: #008000;">&gt;&gt;</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;fullCatListObject&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>returnObj <span style="color: #008000;">==</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                P015.<span style="color: #0000FF;">Modules</span>.<span style="color: #0000FF;">Categories</span>.<span style="color: #0000FF;">Categories</span> _cat <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> P015.<span style="color: #0000FF;">Modules</span>.<span style="color: #0000FF;">Categories</span>.<span style="color: #0000FF;">Categories</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                returnObj <span style="color: #008000;">=</span> _cat.<span style="color: #0000FF;">getCatObject</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                DistCache.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;fullCatListObject&quot;</span>, returnObj, <span style="color: #008000;">new</span> TimeSpan<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">29</span>, <span style="color: #FF0000;">0</span>, <span style="color: #FF0000;">0</span>, <span style="color: #FF0000;">0</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
            <span style="color: #0600FF;">return</span> View<span style="color: #000000;">&#40;</span>returnObj<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
<span style="color: #008000;">&lt;/</span>list<span style="color: #008000;">&gt;</span></pre></td></tr></table></div>

<p>One thing you need to remember when using this library is to have all your objects that you want to save in memcached serialized. For example, this is my CategoryObject class use for the above example:</p>
<p>CategoryObject.cs</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">    <span style="color: #000000;">&#91;</span>Serializable<span style="color: #000000;">&#93;</span>
    <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> CategoryObject
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">string</span> CAT_NAME <span style="color: #000000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
        <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">int</span> CAT_ID <span style="color: #000000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
        <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">int</span> LEVEL <span style="color: #000000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span></pre></div></div>

<p>In case you are using Linq, or more specific, linq to sql, you can open your DBML file in design mode, change the <em>Serialize Mode</em> option to <strong>Unidirectional</strong>.</p>
<p>This works for me, so it should works for you too. Enjoy <img src='http://www.ducdigital.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.ducdigital.com%2F2010%2F01%2F23%2Fmemcached-and-asp-net-mvc%2F&amp;linkname=Memcached%20and%20Asp.net%20mvc"><img src="http://www.ducdigital.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.ducdigital.com/2010/01/23/memcached-and-asp-net-mvc/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Cache individual object in asp.net mvc</title>
		<link>http://www.ducdigital.com/2010/01/14/cache-individual-object-in-asp-net-mvc/</link>
		<comments>http://www.ducdigital.com/2010/01/14/cache-individual-object-in-asp-net-mvc/#comments</comments>
		<pubDate>Thu, 14 Jan 2010 05:37:26 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Asp.net MVC]]></category>
		<category><![CDATA[asp.net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[cache]]></category>
		<category><![CDATA[controller]]></category>
		<category><![CDATA[csharp]]></category>
		<category><![CDATA[httpcontext]]></category>
		<category><![CDATA[linq to sql]]></category>
		<category><![CDATA[linq2sql]]></category>
		<category><![CDATA[mvc]]></category>
		<category><![CDATA[object]]></category>
		<category><![CDATA[oop]]></category>
		<category><![CDATA[outputcache]]></category>
		<category><![CDATA[query]]></category>
		<category><![CDATA[sap.net mvc]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://www.ducdigital.com/?p=218</guid>
		<description><![CDATA[Upon writing a controller for exporting image on the fly, I struggled with the problem that: "Output cache does not cache HttpHeader (in this case, "Location" header)". Which lead me to despair since each time i called the controller to output image, it will have to connect to database and do a couple of query, [...]]]></description>
			<content:encoded><![CDATA[<p>Upon writing a controller for exporting image on the fly, I struggled with the problem that: "Output cache does not cache HttpHeader (in this case, "Location" header)". Which lead me to despair since each time i called the controller to output image, it will have to connect to database and do a couple of query, which is not practical in real life. So finally, i found out that i can easily cache objects into a cache provider in Asp.net Mvc. Very useful, all my queries go back to 0 (traced through Ling2sql profiler). </p>
<p>You can use this piece of code in anywhere of your code where you want to cache any object.<br />
(Notice: this code was used in a controller, so I used HttpContext.Cache. But if you use else where that make this code not working, try HttpContext.Current.Cache)</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;">            <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>HttpContext.<span style="color: #0000FF;">Cache</span><span style="color: #000000;">&#91;</span><span style="color: #666666;">&quot;ObjName&quot;</span><span style="color: #000000;">&#93;</span> <span style="color: #008000;">!=</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                link <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span><span style="color: #000000;">&#41;</span>HttpContext.<span style="color: #0000FF;">Cache</span><span style="color: #000000;">&#91;</span><span style="color: #666666;">&quot;ObjName&quot;</span><span style="color: #000000;">&#93;</span><span style="color: #008000;">;</span>
                <span style="color: #0600FF;">return</span> link<span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
            <span style="color: #0600FF;">else</span>
            <span style="color: #000000;">&#123;</span>
                HttpContext.<span style="color: #0000FF;">Cache</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;ObjName&quot;</span>, link, <span style="color: #0600FF;">null</span>, <span style="color: #000000;">System.<span style="color: #0000FF;">Web</span>.<span style="color: #0000FF;">Caching</span></span>.<span style="color: #0000FF;">Cache</span>.<span style="color: #0000FF;">NoAbsoluteExpiration</span>, <span style="color: #008000;">new</span> TimeSpan<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">30</span>, <span style="color: #FF0000;">0</span>, <span style="color: #FF0000;">0</span>, <span style="color: #FF0000;">0</span>, <span style="color: #FF0000;">0</span><span style="color: #000000;">&#41;</span>, <span style="color: #000000;">System.<span style="color: #0000FF;">Web</span>.<span style="color: #0000FF;">Caching</span></span>.<span style="color: #0000FF;">CacheItemPriority</span>.<span style="color: #0000FF;">High</span>, <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #0600FF;">return</span> link<span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>What it did was to check if the ObjName exist in the context, if not, create one and dump the data into it. Remember when you call back from HttpContext, it's an object so you always need a cast. If you don't know about argument, let the intellisense do the work for you.</p>
<p>Time to exand further about the topic: <a href="http://msdn.microsoft.com/en-us/library/system.web.caching.cache.add(VS.80).aspxx">HttpContext.Cache.Add</a></p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.ducdigital.com%2F2010%2F01%2F14%2Fcache-individual-object-in-asp-net-mvc%2F&amp;linkname=Cache%20individual%20object%20in%20asp.net%20mvc"><img src="http://www.ducdigital.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.ducdigital.com/2010/01/14/cache-individual-object-in-asp-net-mvc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Automatic highlight menu for asp.net mvc.</title>
		<link>http://www.ducdigital.com/2010/01/12/automatic-highlight-menu-for-asp-net-mvc/</link>
		<comments>http://www.ducdigital.com/2010/01/12/automatic-highlight-menu-for-asp-net-mvc/#comments</comments>
		<pubDate>Tue, 12 Jan 2010 07:53:29 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Asp.net MVC]]></category>
		<category><![CDATA[asp.net]]></category>
		<category><![CDATA[automatic]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[dry]]></category>
		<category><![CDATA[extension]]></category>
		<category><![CDATA[helper]]></category>
		<category><![CDATA[highlight]]></category>
		<category><![CDATA[htmlHelper]]></category>
		<category><![CDATA[menu]]></category>
		<category><![CDATA[mvc]]></category>
		<category><![CDATA[sidebar]]></category>
		<category><![CDATA[view]]></category>

		<guid isPermaLink="false">http://www.ducdigital.com/?p=215</guid>
		<description><![CDATA[For a while now I've been wondering how to work out with the menu, so that it can automatic highlight with the least amount of code. So after a while, i come up with this. There are some part which I used the language helper I wrote in previous post. Just go ahead and replace [...]]]></description>
			<content:encoded><![CDATA[<p>For a while now I've been wondering how to work out with the menu, so that it can automatic highlight with the least amount of code. So after a while, i come up with this. There are some part which I used the language helper I <a href="http://www.ducdigital.com/2010/01/10/noob-guide-to-globalization-in-asp-net-mvc/">wrote in previous post</a>. Just go ahead and replace it to whatever that suit your needs.</p>
<p>This one i place on top of my Partial that contain the menu to get the action and controller, so that i can pass this to the extension.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">    <span style="color: #008000;">&lt;</span> <span style="color: #008000;">%</span>  <span style="color: #FF0000;">string</span> currentAction <span style="color: #008000;">=</span> ViewContext.<span style="color: #0000FF;">RouteData</span>.<span style="color: #0000FF;">Values</span><span style="color: #000000;">&#91;</span><span style="color: #666666;">&quot;action&quot;</span><span style="color: #000000;">&#93;</span>.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #FF0000;">string</span> currentController <span style="color: #008000;">=</span> ViewContext.<span style="color: #0000FF;">RouteData</span>.<span style="color: #0000FF;">Values</span><span style="color: #000000;">&#91;</span><span style="color: #666666;">&quot;controller&quot;</span><span style="color: #000000;">&#93;</span>.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008000;">%&gt;</span></pre></div></div>

<p>This is the sidebar Item, basically this will generate a "li" tag with a link and your custom class to indicate whether the link is currently used in the page / highlight. There is a if check in this method, it check for both current action and method if it actually fit the link.<br />
so if you are doing a higher level menu item, in this case, a controller menu, you can just simply compare the controller instead of both.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;">    <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #FF0000;">string</span> SidebarItem<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span> <span style="color: #000000;">System.<span style="color: #0000FF;">Web</span></span>.<span style="color: #0000FF;">Mvc</span>.<span style="color: #0000FF;">HtmlHelper</span> html, <span style="color: #FF0000;">string</span> currentAction, <span style="color: #FF0000;">string</span> currentController, <span style="color: #FF0000;">string</span> action, <span style="color: #FF0000;">string</span> controller, <span style="color: #FF0000;">string</span> languageKey, <span style="color: #0600FF;">params</span> <span style="color: #FF0000;">object</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> args<span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        TagBuilder tb <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> TagBuilder<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;li&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span>.<span style="color: #0000FF;">Equals</span><span style="color: #000000;">&#40;</span>currentAction, action, StringComparison.<span style="color: #0000FF;">OrdinalIgnoreCase</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">&amp;&amp;</span> <span style="color: #FF0000;">string</span>.<span style="color: #0000FF;">Equals</span><span style="color: #000000;">&#40;</span>currentController, controller, StringComparison.<span style="color: #0000FF;">OrdinalIgnoreCase</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            tb.<span style="color: #0000FF;">GenerateId</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;activemenu&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
        <span style="color: #FF0000;">string</span> text <span style="color: #008000;">=</span> html.<span style="color: #0000FF;">Language</span><span style="color: #000000;">&#40;</span>languageKey, args<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #FF0000;">string</span> link <span style="color: #008000;">=</span> html.<span style="color: #0000FF;">ActionLink</span><span style="color: #000000;">&#40;</span>text, action, controller<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">ToHtmlString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        tb.<span style="color: #0000FF;">SetInnerText</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;{0}&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #0600FF;">return</span> <span style="color: #FF0000;">String</span>.<span style="color: #0000FF;">Format</span><span style="color: #000000;">&#40;</span>tb.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>, <span style="color: #666666;">&quot;&lt;span&gt;&quot;</span><span style="color: #008000;">+</span>link<span style="color: #008000;">+</span><span style="color: #666666;">&quot;&lt;/span&gt;&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>And here is the actual sample usage of the code above:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">    <span style="color: #008000;">&lt;</span> <span style="color: #008000;">%=</span> Html.<span style="color: #0000FF;">SidebarItem</span><span style="color: #000000;">&#40;</span>currentAction, currentController, <span style="color: #666666;">&quot;index&quot;</span>, <span style="color: #666666;">&quot;home&quot;</span>, <span style="color: #666666;">&quot;index&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">%&gt;</span></pre></div></div>

<p>This help a lot when you create a menu that can automatic indicate whether you are in that page or not.</p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.ducdigital.com%2F2010%2F01%2F12%2Fautomatic-highlight-menu-for-asp-net-mvc%2F&amp;linkname=Automatic%20highlight%20menu%20for%20asp.net%20mvc."><img src="http://www.ducdigital.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.ducdigital.com/2010/01/12/automatic-highlight-menu-for-asp-net-mvc/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Noob guide to Globalization in Asp.net MVC</title>
		<link>http://www.ducdigital.com/2010/01/10/noob-guide-to-globalization-in-asp-net-mvc/</link>
		<comments>http://www.ducdigital.com/2010/01/10/noob-guide-to-globalization-in-asp-net-mvc/#comments</comments>
		<pubDate>Sat, 09 Jan 2010 21:06:32 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Asp.net MVC]]></category>
		<category><![CDATA[asp.net]]></category>
		<category><![CDATA[culture]]></category>
		<category><![CDATA[globalization]]></category>
		<category><![CDATA[internationalization]]></category>
		<category><![CDATA[Localization]]></category>
		<category><![CDATA[mvc]]></category>
		<category><![CDATA[noob]]></category>
		<category><![CDATA[translation]]></category>
		<category><![CDATA[uiCulture]]></category>
		<category><![CDATA[web form view engine]]></category>

		<guid isPermaLink="false">http://www.ducdigital.com/?p=209</guid>
		<description><![CDATA[Yea. Finally, I've done the Globalization after google and code for 4 hours, it's a pain because there are really (as of when I search) no specific post for this area. So basically in this post, i will gather everything I've done in my Globalization / Localization / Internationalization (whatever you called it is) and [...]]]></description>
			<content:encoded><![CDATA[<p>Yea. Finally, I've done the Globalization after google and code for 4 hours, it's a pain because there are really (as of when I search) no specific post for this area. So basically in this post, i will gather everything I've done in my Globalization / Localization / Internationalization (whatever you called it is) and post here.</p>
<p>First step, we need to make a folder name: <strong>"App_GlobalResources"</strong>, which you can create by right click your project, <em>Add  -> Add ASP.NET Folder -> App_GlobalResources</em></p>
<p>After you created the folder, we need to create <strong>Resource Files</strong> in this folder for the language. Basically, you can see the picture below have 3 files:</p>
<ol>
<li>Language.resx -> this is the default of the language, all the default translation must be in here.</li>
<li>Language.en.resx -> this is the English file. It will override the default translations</li>
<li>Language.vi.resx -> Vietnamese translation, used UTF-8 in here on an UTF-8 website</li>
</ol>
<p><a href="http://www.ducdigital.com/wp-content/uploads/2010/01/Global1.jpg"><img src="http://www.ducdigital.com/wp-content/uploads/2010/01/Global1.jpg" alt="" title="Global1" width="378" height="428" class="aligncenter size-full wp-image-210" /></a></p>
<p>This is the<strong> Language.resx</strong>, which I just have to put the name because it actually doesn't matter, but if for precaution, you can always duplicate one of your language file and replace the <strong>Language.resx</strong> with it so you don't have to worry.<br />
<a href="http://www.ducdigital.com/wp-content/uploads/2010/01/Global2.jpg"><img src="http://www.ducdigital.com/wp-content/uploads/2010/01/Global2.jpg" alt="" title="Global2" width="478" height="174" class="aligncenter size-full wp-image-211" /></a></p>
<p>And here is the picture showing the file <strong>Language.en.resx</strong>. Which I have the Name and the Value<br />
<a href="http://www.ducdigital.com/wp-content/uploads/2010/01/Global3.jpg"><img src="http://www.ducdigital.com/wp-content/uploads/2010/01/Global3.jpg" alt="" title="Global3" width="681" height="302" class="aligncenter size-full wp-image-212" /></a></p>
<p>As you notice the {0} and {1} above, I will explain in the later part.</p>
<p>2nd, we need now is to create a new folder to contain our <em>HtmlExtension </em>and use this to output text string.<br />
In my case, I created a Folder name Helper in my Project root.</p>
<p>Notice: these files are not mine, they are code from, i have modified a little from this source: http://blog.eworldui.net/post/2008/10/ASPNET-MVC-Simplified-Localization-via-ViewEngines.aspx . If ever you need to explain further about WebFormViewEngine or something, you can always go to their website. In my case, to make it as simple as possible, i will cut down this part.</p>
<p><strong> LocalizationWebFormView.cs </strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">using</span> <span style="color: #008080;">System.IO</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Web.Mvc</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF;">namespace</span> Project.<span style="color: #0000FF;">Helper</span>.<span style="color: #0000FF;">Localization</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> LocalizationWebFormView <span style="color: #008000;">:</span> WebFormView
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">internal</span> <span style="color: #0600FF;">const</span> <span style="color: #FF0000;">string</span> ViewPathKey <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;__ViewPath__&quot;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> LocalizationWebFormView<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span> viewPath<span style="color: #000000;">&#41;</span> <span style="color: #008000;">:</span> <span style="color: #0600FF;">base</span><span style="color: #000000;">&#40;</span>viewPath<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> LocalizationWebFormView<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span> viewPath, <span style="color: #FF0000;">string</span> masterPath<span style="color: #000000;">&#41;</span> <span style="color: #008000;">:</span> <span style="color: #0600FF;">base</span><span style="color: #000000;">&#40;</span>viewPath, masterPath<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">override</span> <span style="color: #0600FF;">void</span> Render<span style="color: #000000;">&#40;</span>ViewContext viewContext, TextWriter writer<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #008080; font-style: italic;">// there seems to be a bug with RenderPartial tainting the page's view data</span>
            <span style="color: #008080; font-style: italic;">// so we should capture the current view path, and revert back after rendering</span>
            <span style="color: #FF0000;">string</span> originalViewPath <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span><span style="color: #000000;">&#41;</span> viewContext.<span style="color: #0000FF;">ViewData</span><span style="color: #000000;">&#91;</span>ViewPathKey<span style="color: #000000;">&#93;</span><span style="color: #008000;">;</span>
&nbsp;
            viewContext.<span style="color: #0000FF;">ViewData</span><span style="color: #000000;">&#91;</span>ViewPathKey<span style="color: #000000;">&#93;</span> <span style="color: #008000;">=</span> ViewPath<span style="color: #008000;">;</span>
            <span style="color: #0600FF;">base</span>.<span style="color: #0000FF;">Render</span><span style="color: #000000;">&#40;</span>viewContext, writer<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            viewContext.<span style="color: #0000FF;">ViewData</span><span style="color: #000000;">&#91;</span>ViewPathKey<span style="color: #000000;">&#93;</span> <span style="color: #008000;">=</span> originalViewPath<span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p><strong> LocalizationWebFormViewEngine.cs </strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Web.Mvc</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF;">namespace</span> Project.<span style="color: #0000FF;">Helper</span>.<span style="color: #0000FF;">Localization</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> LocalizationWebFormViewEngine <span style="color: #008000;">:</span> WebFormViewEngine
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">override</span> IView CreateView<span style="color: #000000;">&#40;</span>ControllerContext controllerContext, <span style="color: #FF0000;">string</span> viewPath, <span style="color: #FF0000;">string</span> masterPath<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">return</span> <span style="color: #008000;">new</span> LocalizationWebFormView<span style="color: #000000;">&#40;</span>viewPath, masterPath<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">override</span> IView CreatePartialView<span style="color: #000000;">&#40;</span>ControllerContext controllerContext, <span style="color: #FF0000;">string</span> partialPath<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">return</span> <span style="color: #008000;">new</span> LocalizationWebFormView<span style="color: #000000;">&#40;</span>partialPath, <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p><strong> LocalizationWebFormViewEngine.cs </strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Web.Mvc</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF;">namespace</span> Project.<span style="color: #0000FF;">Helper</span>.<span style="color: #0000FF;">Localization</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> LocalizationWebFormViewEngine <span style="color: #008000;">:</span> WebFormViewEngine
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">override</span> IView CreateView<span style="color: #000000;">&#40;</span>ControllerContext controllerContext, <span style="color: #FF0000;">string</span> viewPath, <span style="color: #FF0000;">string</span> masterPath<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">return</span> <span style="color: #008000;">new</span> LocalizationWebFormView<span style="color: #000000;">&#40;</span>viewPath, masterPath<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">override</span> IView CreatePartialView<span style="color: #000000;">&#40;</span>ControllerContext controllerContext, <span style="color: #FF0000;">string</span> partialPath<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">return</span> <span style="color: #008000;">new</span> LocalizationWebFormView<span style="color: #000000;">&#40;</span>partialPath, <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p><strong> ResourceExtensions.cs </strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Globalization</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Web</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Web.Compilation</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Web.Mvc</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF;">namespace</span> P014.<span style="color: #0000FF;">Helper</span>.<span style="color: #0000FF;">Localization</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #FF0000;">class</span> ResourceExtensions
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #FF0000;">string</span> Resource<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span> Controller controller, <span style="color: #FF0000;">string</span> expression, <span style="color: #0600FF;">params</span> <span style="color: #FF0000;">object</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> args<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            ResourceExpressionFields fields <span style="color: #008000;">=</span> GetResourceFields<span style="color: #000000;">&#40;</span>expression, <span style="color: #666666;">&quot;~/&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF;">return</span> GetGlobalResource<span style="color: #000000;">&#40;</span>fields, args<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #FF0000;">string</span> Resource<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span> HtmlHelper htmlHelper, <span style="color: #FF0000;">string</span> expression, <span style="color: #0600FF;">params</span> <span style="color: #FF0000;">object</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> args<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #FF0000;">string</span> path <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span><span style="color: #000000;">&#41;</span>htmlHelper.<span style="color: #0000FF;">ViewData</span><span style="color: #000000;">&#91;</span>LocalizationWebFormView.<span style="color: #0000FF;">ViewPathKey</span><span style="color: #000000;">&#93;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span>.<span style="color: #0000FF;">IsNullOrEmpty</span><span style="color: #000000;">&#40;</span>path<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
                path <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;~/&quot;</span><span style="color: #008000;">;</span>
&nbsp;
            ResourceExpressionFields fields <span style="color: #008000;">=</span> GetResourceFields<span style="color: #000000;">&#40;</span>expression, path<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #008000;">!</span><span style="color: #FF0000;">string</span>.<span style="color: #0000FF;">IsNullOrEmpty</span><span style="color: #000000;">&#40;</span>fields.<span style="color: #0000FF;">ClassKey</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
                <span style="color: #0600FF;">return</span> GetGlobalResource<span style="color: #000000;">&#40;</span>fields, args<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #0600FF;">return</span> GetLocalResource<span style="color: #000000;">&#40;</span>path, fields, args<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #FF0000;">string</span> Language<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span> HtmlHelper htmlHelper, <span style="color: #FF0000;">string</span> key, <span style="color: #0600FF;">params</span> <span style="color: #FF0000;">object</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> args<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
		    <span style="color: #008080; font-style: italic;">//Replace Language with a name of your choice, if you have lang.en.resx, you should change the value here to &quot;lang&quot;</span>
            <span style="color: #FF0000;">string</span> expression <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Language, &quot;</span> <span style="color: #008000;">+</span> key<span style="color: #008000;">;</span>
            <span style="color: #0600FF;">return</span> Resource<span style="color: #000000;">&#40;</span>htmlHelper, expression, args<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">static</span> <span style="color: #FF0000;">string</span> GetLocalResource<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span> path, ResourceExpressionFields fields, <span style="color: #FF0000;">object</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> args<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">try</span><span style="color: #000000;">&#123;</span>
                <span style="color: #0600FF;">return</span> <span style="color: #FF0000;">string</span>.<span style="color: #0000FF;">Format</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span><span style="color: #000000;">&#41;</span>HttpContext.<span style="color: #0000FF;">GetLocalResourceObject</span><span style="color: #000000;">&#40;</span>path, fields.<span style="color: #0000FF;">ResourceKey</span>, CultureInfo.<span style="color: #0000FF;">CurrentUICulture</span><span style="color: #000000;">&#41;</span>, args<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
            <span style="color: #0600FF;">catch</span> <span style="color: #000000;">&#123;</span> <span style="color: #0600FF;">return</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span><span style="color: #000000;">&#41;</span>HttpContext.<span style="color: #0000FF;">GetLocalResourceObject</span><span style="color: #000000;">&#40;</span>path, fields.<span style="color: #0000FF;">ResourceKey</span>, CultureInfo.<span style="color: #0000FF;">CurrentUICulture</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">static</span> <span style="color: #FF0000;">string</span> GetGlobalResource<span style="color: #000000;">&#40;</span>ResourceExpressionFields fields, <span style="color: #FF0000;">object</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> args<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">try</span><span style="color: #000000;">&#123;</span>
                <span style="color: #0600FF;">return</span> <span style="color: #FF0000;">string</span>.<span style="color: #0000FF;">Format</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span><span style="color: #000000;">&#41;</span>HttpContext.<span style="color: #0000FF;">GetGlobalResourceObject</span><span style="color: #000000;">&#40;</span>fields.<span style="color: #0000FF;">ClassKey</span>, fields.<span style="color: #0000FF;">ResourceKey</span>, CultureInfo.<span style="color: #0000FF;">CurrentUICulture</span><span style="color: #000000;">&#41;</span>, args<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
            <span style="color: #0600FF;">catch</span> <span style="color: #000000;">&#123;</span> <span style="color: #0600FF;">return</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span><span style="color: #000000;">&#41;</span>HttpContext.<span style="color: #0000FF;">GetGlobalResourceObject</span><span style="color: #000000;">&#40;</span>fields.<span style="color: #0000FF;">ClassKey</span>, fields.<span style="color: #0000FF;">ResourceKey</span>, CultureInfo.<span style="color: #0000FF;">CurrentUICulture</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">static</span> ResourceExpressionFields GetResourceFields<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span> expression, <span style="color: #FF0000;">string</span> virtualPath<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            var context <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> ExpressionBuilderContext<span style="color: #000000;">&#40;</span>virtualPath<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            var builder <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> ResourceExpressionBuilder<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF;">return</span> <span style="color: #000000;">&#40;</span>ResourceExpressionFields<span style="color: #000000;">&#41;</span>builder.<span style="color: #0000FF;">ParseExpression</span><span style="color: #000000;">&#40;</span>expression, <span style="color: #008000;">typeof</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span><span style="color: #000000;">&#41;</span>, context<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>What I've added in this code is in the file ResourceExtensions.cs. Which i add a language helper to make you called out from your view easier. Remember to replace Language with a name of your choice, if you have lang.en.resx, you should change the value here to "lang".</p>
<p>Now for the program to finally fire up the Globalization / Localization for the webpage, we need to declare the culture for the program, either you can declare in web.config or you can write a little code in Global.asax</p>
<p>web.config approach:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;system</span> .web<span style="color: #000000; font-weight: bold;">&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;globalization</span> <span style="color: #000066;">uiCulture</span>=<span style="color: #ff0000;">&quot;vi&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/system<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Global.asax</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">        <span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">void</span> Application_BeginRequest<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">Object</span> sender, EventArgs e<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #008080; font-style: italic;">// Application Level language</span>
            <span style="color: #008080; font-style: italic;">// VI here is the language you want to set it on default.</span>
            Thread.<span style="color: #0000FF;">CurrentThread</span>.<span style="color: #0000FF;">CurrentUICulture</span> <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> CultureInfo<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;vi&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span></pre></div></div>

<p>3rd, Configure.... We need to config the view of WFViewEngine to be able to find the Localization classes.<br />
Open web.config and search for</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">&nbsp;
/* Find: */
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;namespaces<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
/* Add this after, where &quot;Project.Helper.Localization&quot; is the class of the files above. */
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">namespace</span>=<span style="color: #ff0000;">&quot;Project.Helper.Localization&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>  
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/namespaces<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Finally! We've done most of it. You can now use the tag below to insert the translation text into the program.</p>

<div class="wp_syntax"><div class="code"><pre class="cshrap" style="font-family:monospace;">&lt; %= Html.Language(&quot;name&quot;) %&gt;</pre></div></div>

<p>For the {0} {1} argument I've mention earlier, I will put some example here:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">// name: argumenttest</span>
<span style="color: #008080; font-style: italic;">// value: This is first argument {0}, 2nd {1}, 3rd &lt;strong&gt;{3} &lt;/strong&gt;</span>
<span style="color: #008000;">&lt;</span> <span style="color: #008000;">%=</span> Html.<span style="color: #0000FF;">Language</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;argumenttest&quot;</span>, <span style="color: #008000;">new</span> <span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> <span style="color: #000000;">&#123;</span> <span style="color: #666666;">&quot;First&quot;</span>, <span style="color: #666666;">&quot;duc&quot;</span>, <span style="color: #666666;">&quot;strong&quot;</span> <span style="color: #000000;">&#125;</span> <span style="color: #008000;">%&gt;</span>
<span style="color: #008080; font-style: italic;">// output: This is first argument First, 2nd duc, 3rd strong</span></pre></div></div>

<p>Now you can have a fully functional globalization / localization without a sweat!<br />
I hope you enjoy this post <img src='http://www.ducdigital.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  !<br />

<a href='http://www.ducdigital.com/2010/01/10/noob-guide-to-globalization-in-asp-net-mvc/global1/' title='Global1'><img width="150" height="150" src="http://www.ducdigital.com/wp-content/uploads/2010/01/Global1-150x150.jpg" class="attachment-thumbnail" alt="" title="Global1" /></a>
<a href='http://www.ducdigital.com/2010/01/10/noob-guide-to-globalization-in-asp-net-mvc/global2/' title='Global2'><img width="150" height="150" src="http://www.ducdigital.com/wp-content/uploads/2010/01/Global2-150x150.jpg" class="attachment-thumbnail" alt="" title="Global2" /></a>
<a href='http://www.ducdigital.com/2010/01/10/noob-guide-to-globalization-in-asp-net-mvc/global3/' title='Global3'><img width="150" height="150" src="http://www.ducdigital.com/wp-content/uploads/2010/01/Global3-150x150.jpg" class="attachment-thumbnail" alt="" title="Global3" /></a>
</p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.ducdigital.com%2F2010%2F01%2F10%2Fnoob-guide-to-globalization-in-asp-net-mvc%2F&amp;linkname=Noob%20guide%20to%20Globalization%20in%20Asp.net%20MVC"><img src="http://www.ducdigital.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.ducdigital.com/2010/01/10/noob-guide-to-globalization-in-asp-net-mvc/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Builtin Async Controller in ASP.net MVC 2</title>
		<link>http://www.ducdigital.com/2009/12/24/builtin-async-controller-in-asp-net-mvc-2/</link>
		<comments>http://www.ducdigital.com/2009/12/24/builtin-async-controller-in-asp-net-mvc-2/#comments</comments>
		<pubDate>Thu, 24 Dec 2009 02:00:42 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Asp.net MVC]]></category>
		<category><![CDATA[action]]></category>
		<category><![CDATA[asp.net]]></category>
		<category><![CDATA[async]]></category>
		<category><![CDATA[Asynchronous]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[controller]]></category>
		<category><![CDATA[mvc]]></category>

		<guid isPermaLink="false">http://www.ducdigital.com/?p=196</guid>
		<description><![CDATA[Well, it's Christmas Eve at the time I post this post in my place. I hope you enjoy your Christmas with your family and happy new year to all of you who read this post of mine.
------------------------
One thing that make me feel more powerful when using ASP.net MVC is the newly introduce Asynchronous Controller Action. [...]]]></description>
			<content:encoded><![CDATA[<p>Well, it's Christmas Eve at the time I post this post in my place. I hope you enjoy your Christmas with your family and happy new year to all of you who read this post of mine.</p>
<p>------------------------</p>
<p>One thing that make me feel more powerful when using ASP.net MVC is the newly introduce Asynchronous Controller Action. </p>
<p>Imagine, you have a front page with multiple widget, like news, weather, personal information, new forum thread etc... You are going to run it from top to bottom, query, query... Your basic solution for this is to query news first since it's kinda important, then weather, etc...</p>
<p><strong>Why it's not a good solution?</strong> Because if you going to query everything like that, your program need to wait for each query to finish before continue to work with the code behind...</p>
<p><strong>Better Solution?</strong> I could suggest you using Async Controller in this case. Separate each query into different Data Context, query to the database, Close Current Data Context, and process the info with code behind, separately and process at the same time. This helps you bring down processing time twice or thrice as fast than the normal approach...</p>
<p>Asynchronous Process has been introduce to ASP.net long before, but now, apply it to asp.net MVC even easier than what you really expect.</p>
<ul>
<li>Inherit to "AsyncController" instead of "Controller" class</li>
<li>Write async method</li>
<li>Write Complete method</li>
<li>Write functions to handle async request</li>
</ul>
<p>First step:</p>
<p>Look out for the head of your controller, you will always see this:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> MyController <span style="color: #008000;">:</span> Controller</pre></div></div>

<p>change it to:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> MyController <span style="color: #008000;">:</span> AsyncController</pre></div></div>

<p>Don't worry because everything will work just as normal even if you don't use AsyncController.</p>
<p>2nd Step, write the MethodAsync and MethodCompleted. The important is the prefix in this case, Async and Completed. </p>
<ul>
<li><strong>Method </strong>is the action name, like Create, Delete, Details</li>
<li><strong>Async </strong>is in Void type, and everything request first will come to this void method, you can get the input from form, url here in this method. Async will pass parameter to Completed using <strong>AsyncManager.Parameter</strong>s that you can see later in this article</li>
<li><strong>Completed </strong> is an ActionResult method. just like your normal Create, Delete action. You can return a View or RedirectResult here. The param of this method corresponding to the <em>AsyncManager.Parameter </em>that was used in <em>MethodAsync</em></li>
</ul>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;">&nbsp;
<span style="color: #008080; font-style: italic;">// Http://local/Controller/Method/</span>
<span style="color: #008080; font-style: italic;">// As you can see i am using the attribute that can be use in the normal Actions</span>
<span style="color: #000000;">&#91;</span>AcceptVerbs<span style="color: #000000;">&#40;</span>HttpVerbs.<span style="color: #0000FF;">Post</span><span style="color: #000000;">&#41;</span>, ActionName<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Method&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
&nbsp;
<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">void</span> MethodAsync<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span> id, <span style="color: #FF0000;">string</span> hello<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
&nbsp;
	<span style="color: #008080; font-style: italic;">// This Increment() use to identify how many async process are there, </span>
	<span style="color: #008080; font-style: italic;">// once everything is back to 0, MethodCompleted is fire-up</span>
&nbsp;
	AsyncManager.<span style="color: #0000FF;">OutstandingOperations</span>.<span style="color: #0000FF;">Increment</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
	<span style="color: #008080; font-style: italic;">// This used to handle functions that are not Async Ready</span>
    <span style="color: #008080; font-style: italic;">// since they don't have any async event ready.</span>
	<span style="color: #008080; font-style: italic;">// using this you can start with any method.</span>
&nbsp;
	<span style="color: #008080; font-style: italic;">// the first int, string is the parameter data type, the last bool is the return type.</span>
	<span style="color: #008080; font-style: italic;">// DoTestAsync is the method name that we going to write later on</span>
&nbsp;
    Func<span style="color: #008000;">&lt;</span><span style="color: #FF0000;">int</span> , <span style="color: #FF0000;">string</span>, <span style="color: #FF0000;">bool</span><span style="color: #008000;">&gt;</span> doTestHandler <span style="color: #008000;">=</span> DoTestAsync<span style="color: #008000;">;</span>
&nbsp;
	<span style="color: #008080; font-style: italic;">// Begin async</span>
	<span style="color: #008080; font-style: italic;">// ID, Hello is the param passing to method DoTestAsync</span>
    doTestHandler.<span style="color: #0000FF;">BeginInvoke</span><span style="color: #000000;">&#40;</span>id, hello, ar <span style="color: #008000;">=&gt;</span>
    <span style="color: #000000;">&#123;</span>
&nbsp;
        var handler <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span>Func<span style="color: #008000;">&lt;/</span><span style="color: #FF0000;">int</span><span style="color: #008000;">&gt;&lt;</span><span style="color: #FF0000;">int</span> , <span style="color: #FF0000;">string</span>, <span style="color: #FF0000;">bool</span><span style="color: #008000;">&gt;</span><span style="color: #000000;">&#41;</span>ar.<span style="color: #0000FF;">AsyncState</span><span style="color: #008000;">;</span>
&nbsp;
		<span style="color: #008080; font-style: italic;">// AsyncManager.Parameters[&quot;returned&quot;] now cantaining the result of </span>
		<span style="color: #008080; font-style: italic;">// method DoTestAsync after finish the process. The datatype is bool.</span>
        AsyncManager.<span style="color: #0000FF;">Parameters</span><span style="color: #000000;">&#91;</span><span style="color: #666666;">&quot;returned&quot;</span><span style="color: #000000;">&#93;</span> <span style="color: #008000;">=</span> handler.<span style="color: #0000FF;">EndInvoke</span><span style="color: #000000;">&#40;</span>ar<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        AsyncManager.<span style="color: #0000FF;">OutstandingOperations</span>.<span style="color: #0000FF;">Decrement</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>, doTagHandler<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #008080; font-style: italic;">// This will process after the Async finished. The param of</span>
<span style="color: #008080; font-style: italic;">// this method is what we have used with AsyncManager.Parameters,</span>
<span style="color: #008080; font-style: italic;">// in this case, returned with type bool</span>
<span style="color: #0600FF;">public</span> ActionResult MethodCompleted<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">bool</span> returned<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #008080; font-style: italic;">// You can actually make use of the param here to make some ViewData or something</span>
	returned <span style="color: #008000;">=</span> <span style="color: #008000;">!</span>returned<span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #008080; font-style: italic;">// Since it's a ActionResult, i must return a View or something related.</span>
	<span style="color: #008080; font-style: italic;">// return View(); -&gt; will use the default view (Controller\Method.aspx)</span>
&nbsp;
	<span style="color: #008080; font-style: italic;">// i want to show some Content:</span>
	<span style="color: #0600FF;">return</span> Content<span style="color: #000000;">&#40;</span>returned.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #008080; font-style: italic;">// Now we will write the method for our async controller </span>
<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">bool</span> DoTestAsync<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span> a, <span style="color: #FF0000;">string</span> b<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #008080; font-style: italic;">// Everything you need to do with the param in here, </span>
	<span style="color: #008080; font-style: italic;">// include query to your database or anything you can</span>
	<span style="color: #008080; font-style: italic;">// posibly think of. For me, i will just return something.</span>
&nbsp;
	<span style="color: #0600FF;">return</span> true<span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span>
<span style="color: #008000;">&lt;/</span><span style="color: #FF0000;">int</span><span style="color: #008000;">&gt;</span></pre></td></tr></table></div>

<p>The result of this is:</p>
<pre>
"False"
</pre>
<p>Isn't it simple, what you need is just to follow this and there you go, you can now have a Web application that run twice or thrice as fast.</p>
<p>Good luck...</p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.ducdigital.com%2F2009%2F12%2F24%2Fbuiltin-async-controller-in-asp-net-mvc-2%2F&amp;linkname=Builtin%20Async%20Controller%20in%20ASP.net%20MVC%202"><img src="http://www.ducdigital.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.ducdigital.com/2009/12/24/builtin-async-controller-in-asp-net-mvc-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>NVARCHAR(MAX) now&#8230;</title>
		<link>http://www.ducdigital.com/2009/12/22/nvarcharmax-now/</link>
		<comments>http://www.ducdigital.com/2009/12/22/nvarcharmax-now/#comments</comments>
		<pubDate>Tue, 22 Dec 2009 13:19:52 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[microsoft]]></category>
		<category><![CDATA[mssql]]></category>
		<category><![CDATA[mssql2008]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[sqlserver]]></category>
		<category><![CDATA[Structured Query Language]]></category>
		<category><![CDATA[t-sql]]></category>

		<guid isPermaLink="false">http://www.ducdigital.com/?p=188</guid>
		<description><![CDATA[Recently, I need to write a Trigger to duplicate and save a copy of revision automatically into the database, and at that time, i encoutered an error:
Cannot use text, ntext, or image columns in the ‘inserted’ and ‘deleted’ tables.
This cause me so much trouble since what else should i use if I am not allowed [...]]]></description>
			<content:encoded><![CDATA[<p>Recently, I need to write a Trigger to duplicate and save a copy of revision automatically into the database, and at that time, i encoutered an error:</p>
<blockquote><p>Cannot use text, ntext, or image columns in the ‘inserted’ and ‘deleted’ tables.</p></blockquote>
<p>This cause me so much trouble since what else should i use if I am not allowed to use text/ntext? This make me wandering around google for a while, and finally there is a solution...</p>
<p>The NTEXT, TEXT, IMAGE is deprecated since 2005 and will be remove in the future release, maybe 2008R2 since MSSQL2008 still work fine with NTEXT, TEXT</p>
<ul>
<li>NTEXT -&gt; replaced by NVARCHAR(MAX)</li>
<li>TEXT -&gt; replaced by VARCHAR(MAX)</li>
<li>IMAGE -&gt; replaced by VARBINARY(MAX)</li>
</ul>
<p>And of course, for those who wondering, the maximum limit of VARCHAR is 8000 and NVARCHAR is 4000 (2 bytes for each unicode character) due to SQL Server uses 8KB page to store data to disk. But of course, Varchar(MAX), NVarchar(MAX) and VarBinary(MAX) data types in SQL Server 2005 which allows you to save upto 2GB in a single variable. The best part is that It allows you to use these data types as stored procedure parameters, internal variables etc.</p>
<p>So I suggest you should stop using NTEXT and TEXT and switch to NVARCHAR/VARCHAR soon!</p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.ducdigital.com%2F2009%2F12%2F22%2Fnvarcharmax-now%2F&amp;linkname=NVARCHAR%28MAX%29%20now%26%238230%3B"><img src="http://www.ducdigital.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.ducdigital.com/2009/12/22/nvarcharmax-now/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Convert INT to VARCHAR in SQL (MSSQL)</title>
		<link>http://www.ducdigital.com/2009/12/20/convert-int-to-varchar-in-sql-mssql/</link>
		<comments>http://www.ducdigital.com/2009/12/20/convert-int-to-varchar-in-sql-mssql/#comments</comments>
		<pubDate>Sun, 20 Dec 2009 13:10:46 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[SQL]]></category>
		<category><![CDATA[microsoft]]></category>
		<category><![CDATA[mssql]]></category>
		<category><![CDATA[mssql2008]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[sqlserver]]></category>
		<category><![CDATA[Structured Query Language]]></category>
		<category><![CDATA[t-sql]]></category>

		<guid isPermaLink="false">http://www.ducdigital.com/?p=186</guid>
		<description><![CDATA[At some point you will need to change INT to VARCHAR for the purpose of manipulation like substring or to display it in the status windows when execute of stored procedure or trigger...
here is the code which you can use to convert / cast the INT to VARCHAR:

CONVERT&#40;TYPE, VALUE&#41;

in this case ( my case ), [...]]]></description>
			<content:encoded><![CDATA[<p>At some point you will need to change INT to VARCHAR for the purpose of manipulation like substring or to display it in the status windows when execute of stored procedure or trigger...</p>
<p>here is the code which you can use to convert / cast the INT to VARCHAR:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;">CONVERT<span style="color: #66cc66;">&#40;</span>TYPE<span style="color: #66cc66;">,</span> VALUE<span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>in this case ( my case ), this was used:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;">	PRINT <span style="color: #ff0000;">'New revision updated for post id '</span> <span style="color: #66cc66;">+</span> CONVERT<span style="color: #66cc66;">&#40;</span>VARCHAR<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">20</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> @intPID<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">+</span> <span style="color: #ff0000;">'!'</span></pre></div></div>

<p>Good luck</p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.ducdigital.com%2F2009%2F12%2F20%2Fconvert-int-to-varchar-in-sql-mssql%2F&amp;linkname=Convert%20INT%20to%20VARCHAR%20in%20SQL%20%28MSSQL%29"><img src="http://www.ducdigital.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.ducdigital.com/2009/12/20/convert-int-to-varchar-in-sql-mssql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
