<?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>Florent Clairambault &#187; lighttpd</title>
	<atom:link href="http://florent.clairambault.fr/tag/lighttpd/feed" rel="self" type="application/rss+xml" />
	<link>http://florent.clairambault.fr</link>
	<description></description>
	<lastBuildDate>Sat, 04 Feb 2012 19:56:37 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4-alpha-19719</generator>
		<item>
		<title>Lighttpd + Mono ASP.Net : The right configuration</title>
		<link>http://florent.clairambault.fr/lighttpd-mono-asp-net-the-right-configuration?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=lighttpd-mono-asp-net-the-right-configuration</link>
		<comments>http://florent.clairambault.fr/lighttpd-mono-asp-net-the-right-configuration#comments</comments>
		<pubDate>Mon, 18 May 2009 18:34:55 +0000</pubDate>
		<dc:creator>Florent Clairambault</dc:creator>
				<category><![CDATA[English]]></category>
		<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[C# .Net]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[lighttpd]]></category>
		<category><![CDATA[Mono]]></category>

		<guid isPermaLink="false">http://florent.clairambault.fr/?p=799</guid>
		<description><![CDATA[As I already told before, I love the Mono project. It enables to run the powerful Microsoft .Net Framework on UNIX/Linux/BSD systems. I recently wanted to test a very cool feature of ASP.Net on a mono server. So I did a little 1 apt-get install lighttpd mono-fastcgi-server2 -y The feature I wanted to try was [...]]]></description>
			<content:encoded><![CDATA[<p>As I already told before, I love the <a href="http://www.mono-project.com/">Mono project</a>. It enables to run the powerful Microsoft .Net Framework on UNIX/Linux/BSD systems.</p>
<p>I recently wanted to test a very cool feature of ASP.Net on a mono server. So I did a little</p>

<div class="wp_codebox"><table><tr id="p7996"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p799code6"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> lighttpd mono-fastcgi-server2 <span style="color: #660033;">-y</span></pre></td></tr></table></div>

<p>The feature I wanted to try was a web scripting method ( with the &#8220;[WebMethod]&#8221; attribute) exporting some JSON directly from your method return value.</p>
<p>Here is the web scripting method declaration :</p>

<div class="wp_codebox"><table><tr id="p7997"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code" id="p799code7"><pre class="csharp" style="font-family:monospace;">&nbsp;
<span style="color: #008000;">&#91;</span>ScriptService<span style="color: #008000;">&#93;</span>
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">partial</span> <span style="color: #6666cc; font-weight: bold;">class</span> _Default<span style="color: #008000;">:</span>Page <span style="color: #008000;">&#123;</span>
&nbsp;
	<span style="color: #008000;">&#91;</span>WebMethod<span style="color: #008000;">&#93;</span>
	<span style="color: #008000;">&#91;</span>ScriptMethod<span style="color: #008000;">&#40;</span> ResponseFormat <span style="color: #008000;">=</span> ResponseFormat<span style="color: #008000;">.</span><span style="color: #0000FF;">Json</span>, UseHttpGet <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">false</span> <span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span>
	<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">String</span> TestMethod<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		<span style="color: #0600FF; font-weight: bold;">return</span> DateTime<span style="color: #008000;">.</span><span style="color: #0000FF;">Now</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ToString</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>And here is the javascript / JQuery code that gets the data :</p>

<div class="wp_codebox"><table><tr id="p7998"><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
</pre></td><td class="code" id="p799code8"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;toto&quot;</span><span style="color: #339933;">&gt;&lt;/</span>div<span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
    <span style="color: #003366; font-weight: bold;">function</span> doIt<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        $<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            $.<span style="color: #660066;">ajax</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
                type<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;POST&quot;</span><span style="color: #339933;">,</span>
                url<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;/Default.aspx/TestMethod&quot;</span><span style="color: #339933;">,</span>
                contentType<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;application/json; charset=utf-8&quot;</span><span style="color: #339933;">,</span>
                data<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;{}&quot;</span><span style="color: #339933;">,</span>
                dataType<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;json&quot;</span><span style="color: #339933;">,</span>
                success<span style="color: #339933;">:</span> AjaxSucceeded<span style="color: #339933;">,</span>
                error<span style="color: #339933;">:</span> AjaxFailed
            <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #003366; font-weight: bold;">function</span> AjaxSucceeded<span style="color: #009900;">&#40;</span>result<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;toto&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">innerHTML</span> <span style="color: #339933;">=</span> result.<span style="color: #660066;">d</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #003366; font-weight: bold;">function</span> AjaxFailed<span style="color: #009900;">&#40;</span>result<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
           document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;toto&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">innerHTML</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;Error : &quot;</span><span style="color: #339933;">+</span>result.<span style="color: #000066;">status</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">' '</span> <span style="color: #339933;">+</span> result.<span style="color: #660066;">statusText</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        setTimeout<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;doIt()&quot;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">1000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    doIt<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>In my /etc/lighttpd/conf-enabled/10-fastcgi.conf file, I had this :</p>

<div class="wp_codebox"><table><tr id="p7999"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
</pre></td><td class="code" id="p799code9"><pre class="txt" style="font-family:monospace;">server.modules   += ( &quot;mod_fastcgi&quot; )
fastcgi.server    = (
        &quot;&quot; =&gt; ((
                &quot;socket&quot; =&gt; mono_shared_dir + &quot;fastcgi-mono-server&quot;,
                &quot;bin-path&quot; =&gt; mono_fastcgi_server,
                &quot;bin-environment&quot; =&gt; (
                        &quot;PATH&quot; =&gt; &quot;/bin:/usr/bin:&quot; + mono_dir + &quot;bin&quot;,
                        &quot;LD_LIBRARY_PATH&quot; =&gt; mono_dir + &quot;lib:&quot;,
                        &quot;MONO_SHARED_DIR&quot; =&gt; mono_shared_dir,
                        &quot;MONO_FCGI_LOGLEVELS&quot; =&gt; &quot;Standard&quot;,
                        &quot;MONO_FCGI_LOGFILE&quot; =&gt; &quot;/var/log/lighttpd/mono.log&quot;,
                        &quot;MONO_FCGI_ROOT&quot; =&gt; mono_fcgi_root,
                        &quot;MONO_FCGI_APPLICATIONS&quot; =&gt; mono_fcgi_applications
                ),
                &quot;max-procs&quot; =&gt; 1,
                &quot;check-local&quot; =&gt; &quot;disable&quot;
        ))
)</pre></td></tr></table></div>

<p>Everytime I launched a call from javascript, I got (with JS) I got a &#8220;405 Method not allowed&#8221;. Well, that was pretty disturbing. Mostly because <a href="http://www.google.com/search?q=405+method+not+allowed+mono+WebMethod">a google search on this</a> didn&#8217;t give me anything.<br />
My first thought was that mono didn&#8217;t react the same way the .Net framework does. But this isn&#8217;t it. It came from my crappy lighttpd config file. It didn&#8217;t search for the Default.aspx file but for the Default.aspx/TesMethod.<br />
What you need to do is set :</p>

<div class="wp_codebox"><table><tr id="p79910"><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" id="p799code10"><pre class="txt" style="font-family:monospace;">fastcgi.server    = (
        &quot;.aspx&quot; =&gt; ((
            # Everything you have in your file (like my file above)
        )
&nbsp;
fastcgi.map-extensions = (
        &quot;.asmx&quot;   =&gt; &quot;.aspx&quot;,
        &quot;.ashx&quot;   =&gt; &quot;.aspx&quot;,
        &quot;.asax&quot;   =&gt; &quot;.aspx&quot;,
        &quot;.ascx&quot;   =&gt; &quot;.aspx&quot;,
        &quot;.soap&quot;   =&gt; &quot;.aspx&quot;,
        &quot;.rem&quot;    =&gt; &quot;.aspx&quot;,
        &quot;.axd&quot;    =&gt; &quot;.aspx&quot;,
        &quot;.cs&quot;     =&gt; &quot;.aspx&quot;,
        &quot;.config&quot; =&gt; &quot;.aspx&quot;,
        &quot;.dll&quot;    =&gt; &quot;.aspx&quot;
)</pre></td></tr></table></div>

<p>And that will even improve your performances because any other file will be handled directly by lighttpd.</p>
<p>One quick note : There&#8217;s something weird with VS2008 WebDev.WebServer.Exe, the WebMethod request takes at least 1.0s to complete. On the same host with XSP, it&#8217;s around 15 ms. And on the Celeron 2.6Ghz linux server with lighttpd it&#8217;s around 12 ms. And on a IIS 7 server (bundled with Windows 7), it takes 12 ms. So why is the Visual Studio&#8217;s WebDev.WebServer so slow ?</p>
<p>By the way, why should we use a Linux + lighttpd + Mono server when we can use a Windows + IIS + ASP.Net server ? The reason is mainly that for the same usage, Linux consumes less resources and it&#8217;s easier to customize to suit your needs.</p>
<p>An other question you might have : Why use JQuery + JSON when you can use everything in the Microsoft AJAX Framework ? The main reason is that I really have the feeling to lose control with Microsoft AJAX Framework, I don&#8217;t like the huge automatically generated code. And it doesn&#8217;t make really fast web interfaces. With JQuery, everything goes faster and it&#8217;s way more simpler to understand (and debug).</p>
<p>Related :<br />
- <a href="http://dotnetslackers.com/articles/ajax/Using-jQuery-with-ASP-NET.aspx#953">Using JQuery with ASP.Net</a></p>
]]></content:encoded>
			<wfw:commentRss>http://florent.clairambault.fr/lighttpd-mono-asp-net-the-right-configuration/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced
Database Caching 1/13 queries in 0.005 seconds using disk: basic
Object Caching 517/528 objects using disk: basic

Served from: florent.clairambault.fr @ 2012-02-07 11:00:15 -->
