<?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; JSON</title>
	<atom:link href="http://florent.clairambault.fr/tag/json/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>Access your Google Latitude position from a .Net app</title>
		<link>http://florent.clairambault.fr/access-your-google-latitude-position-from-a-net-app?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=access-your-google-latitude-position-from-a-net-app</link>
		<comments>http://florent.clairambault.fr/access-your-google-latitude-position-from-a-net-app#comments</comments>
		<pubDate>Mon, 22 Jun 2009 21:32:41 +0000</pubDate>
		<dc:creator>Florent Clairambault</dc:creator>
				<category><![CDATA[English]]></category>
		<category><![CDATA[C# .Net]]></category>
		<category><![CDATA[geolocation]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[Google Latitude]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[VS2010]]></category>

		<guid isPermaLink="false">http://florent.clairambault.fr/?p=1213</guid>
		<description><![CDATA[When I saw that Google Latitude now enables you to access your data by a JSON feed, I decided to make it communicate with a little GPS tracking project of mine. I&#8217;m really found of all these ways we now have to make anything communicate with anything. You can build interfaces from any system to [...]]]></description>
			<content:encoded><![CDATA[<p>When I saw that Google Latitude now enables you to access your data by a JSON feed, I decided to make it communicate with a little GPS tracking project of mine.</p>
<p>I&#8217;m really found of all these ways we now have to make anything communicate with anything. You can build interfaces from any system to any other system really easily.</p>
<p>This code enables you to automatically get your GPS position (or the position of a friend) from your JSON Latitude feed. To be able to do that, you have to <a href="http://www.google.com/latitude/apps/badge">enable your KML/JSON feed</a>.<br />
It requires .Net 3.5&#8242;s System.Web.Extensions</p>

<div class="wp_codebox"><table><tr id="p12132"><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
64
65
66
67
68
69
70
71
72
73
74
75
76
</pre></td><td class="code" id="p1213code2"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Collections.Generic</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Text</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Web.Script.Serialization</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Net</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.IO</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">namespace</span> LatitudeReader <span style="color: #008000;">&#123;</span>
	<span style="color: #6666cc; font-weight: bold;">class</span> Program <span style="color: #008000;">&#123;</span>
		<span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> Main<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
&nbsp;
			Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span> <span style="color: #666666;">&quot;What is your user id ?&quot;</span> <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
			var userId <span style="color: #008000;">=</span> Console<span style="color: #008000;">.</span><span style="color: #0000FF;">ReadLine</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
			<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span> userId <span style="color: #008000;">==</span> <span style="color: #6666cc; font-weight: bold;">String</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Empty</span> <span style="color: #008000;">&#41;</span>
				userId <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;5616045291659744796&quot;</span><span style="color: #008000;">;</span>
&nbsp;
			<span style="color: #008080; font-style: italic;">// Url of the JSON Latitude feed</span>
			var url <span style="color: #008000;">=</span> <span style="color: #6666cc; font-weight: bold;">String</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Format</span><span style="color: #008000;">&#40;</span> <span style="color: #666666;">&quot;http://www.google.com/latitude/apps/badge/api?user={0}&amp;type=json&quot;</span>, userId <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
			<span style="color: #008080; font-style: italic;">// We download the file</span>
			var ms <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> MemoryStream<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
			Download<span style="color: #008000;">&#40;</span> url, ms <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
			<span style="color: #008080; font-style: italic;">// JSON in text format</span>
			var textContent <span style="color: #008000;">=</span> UTF8Encoding<span style="color: #008000;">.</span><span style="color: #0000FF;">UTF8</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetString</span><span style="color: #008000;">&#40;</span> ms<span style="color: #008000;">.</span><span style="color: #0000FF;">ToArray</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
			<span style="color: #008080; font-style: italic;">// We convert the JSON text file to an object</span>
			<span style="color: #008080; font-style: italic;">// It returns </span>
			var jss <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> JavaScriptSerializer<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
			var jsonContent <span style="color: #008000;">=</span> jss<span style="color: #008000;">.</span><span style="color: #0000FF;">DeserializeObject</span><span style="color: #008000;">&#40;</span> textContent <span style="color: #008000;">&#41;</span> <span style="color: #0600FF; font-weight: bold;">as</span> Dictionary<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">String</span>, <span style="color: #6666cc; font-weight: bold;">Object</span><span style="color: #008000;">&gt;;</span>
&nbsp;
			<span style="color: #008080; font-style: italic;">// We get the data</span>
			var features <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span> jsonContent<span style="color: #008000;">&#91;</span> <span style="color: #666666;">&quot;features&quot;</span> <span style="color: #008000;">&#93;</span> <span style="color: #0600FF; font-weight: bold;">as</span> <span style="color: #6666cc; font-weight: bold;">object</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">&#41;</span><span style="color: #008000;">&#91;</span> <span style="color: #FF0000;">0</span> <span style="color: #008000;">&#93;</span> <span style="color: #0600FF; font-weight: bold;">as</span> Dictionary<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">string</span>, <span style="color: #6666cc; font-weight: bold;">object</span><span style="color: #008000;">&gt;;</span>
			var geometry <span style="color: #008000;">=</span> features<span style="color: #008000;">&#91;</span> <span style="color: #666666;">&quot;geometry&quot;</span> <span style="color: #008000;">&#93;</span> <span style="color: #0600FF; font-weight: bold;">as</span> Dictionary<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">string</span>, <span style="color: #6666cc; font-weight: bold;">object</span><span style="color: #008000;">&gt;;</span>
			var coordinates <span style="color: #008000;">=</span> geometry<span style="color: #008000;">&#91;</span> <span style="color: #666666;">&quot;coordinates&quot;</span> <span style="color: #008000;">&#93;</span> <span style="color: #0600FF; font-weight: bold;">as</span> <span style="color: #6666cc; font-weight: bold;">object</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span>
			var lon <span style="color: #008000;">=</span> coordinates<span style="color: #008000;">&#91;</span> <span style="color: #FF0000;">0</span> <span style="color: #008000;">&#93;</span> <span style="color: #0600FF; font-weight: bold;">as</span> <span style="color: #6666cc; font-weight: bold;">decimal</span><span style="color: #008000;">?;</span>
			var lat <span style="color: #008000;">=</span> coordinates<span style="color: #008000;">&#91;</span> <span style="color: #FF0000;">1</span> <span style="color: #008000;">&#93;</span> <span style="color: #0600FF; font-weight: bold;">as</span> <span style="color: #6666cc; font-weight: bold;">decimal</span><span style="color: #008000;">?;</span>
&nbsp;
			<span style="color: #008080; font-style: italic;">// And then the timestamp</span>
			var properties <span style="color: #008000;">=</span> features<span style="color: #008000;">&#91;</span> <span style="color: #666666;">&quot;properties&quot;</span> <span style="color: #008000;">&#93;</span> <span style="color: #0600FF; font-weight: bold;">as</span> Dictionary<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">string</span>, <span style="color: #6666cc; font-weight: bold;">object</span><span style="color: #008000;">&gt;;</span>
			var date <span style="color: #008000;">=</span> ConvertFromUnixTimestamp<span style="color: #008000;">&#40;</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">double</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span> properties<span style="color: #008000;">&#91;</span> <span style="color: #666666;">&quot;timeStamp&quot;</span> <span style="color: #008000;">&#93;</span> <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
			<span style="color: #008080; font-style: italic;">// We convert the UTC date to local time</span>
			date <span style="color: #008000;">=</span> date<span style="color: #008000;">.</span><span style="color: #0000FF;">ToLocalTime</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
			Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span> <span style="color: #666666;">&quot;{0} : {1} x {2}&quot;</span>, date, lat, lon <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #008000;">&#125;</span>
&nbsp;
		<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> DateTime ConvertFromUnixTimestamp<span style="color: #008000;">&#40;</span> <span style="color: #6666cc; font-weight: bold;">double</span> timestamp <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
			DateTime origin <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> DateTime<span style="color: #008000;">&#40;</span> <span style="color: #FF0000;">1970</span>, <span style="color: #FF0000;">1</span>, <span style="color: #FF0000;">1</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: #008000;">&#41;</span><span style="color: #008000;">;</span>
			<span style="color: #0600FF; font-weight: bold;">return</span> origin<span style="color: #008000;">.</span><span style="color: #0000FF;">AddSeconds</span><span style="color: #008000;">&#40;</span> timestamp <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #008000;">&#125;</span>
&nbsp;
		<span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">const</span> <span style="color: #6666cc; font-weight: bold;">int</span> BUFFER_SIZE <span style="color: #008000;">=</span> <span style="color: #FF0000;">1024</span><span style="color: #008000;">;</span>
&nbsp;
		<span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> Download<span style="color: #008000;">&#40;</span> <span style="color: #6666cc; font-weight: bold;">string</span> url, Stream writeStream <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
			var request <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span>HttpWebRequest<span style="color: #008000;">&#41;</span> WebRequest<span style="color: #008000;">.</span><span style="color: #0000FF;">Create</span><span style="color: #008000;">&#40;</span> url <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
			var response <span style="color: #008000;">=</span> request<span style="color: #008000;">.</span><span style="color: #0000FF;">GetResponse</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
			var readStream <span style="color: #008000;">=</span> response<span style="color: #008000;">.</span><span style="color: #0000FF;">GetResponseStream</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
			var data <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> <span style="color: #6666cc; font-weight: bold;">Byte</span><span style="color: #008000;">&#91;</span> BUFFER_SIZE <span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span>
&nbsp;
			<span style="color: #6666cc; font-weight: bold;">int</span> n<span style="color: #008000;">;</span>
			<span style="color: #0600FF; font-weight: bold;">do</span> <span style="color: #008000;">&#123;</span>
				n <span style="color: #008000;">=</span> readStream<span style="color: #008000;">.</span><span style="color: #0000FF;">Read</span><span style="color: #008000;">&#40;</span> data, <span style="color: #FF0000;">0</span>, BUFFER_SIZE <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
				writeStream<span style="color: #008000;">.</span><span style="color: #0000FF;">Write</span><span style="color: #008000;">&#40;</span> data, <span style="color: #FF0000;">0</span>, n <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
			<span style="color: #008000;">&#125;</span> <span style="color: #0600FF; font-weight: bold;">while</span> <span style="color: #008000;">&#40;</span> n <span style="color: #008000;">&gt;</span> <span style="color: #FF0000;">0</span> <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
			writeStream<span style="color: #008000;">.</span><span style="color: #0000FF;">Flush</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
			readStream<span style="color: #008000;">.</span><span style="color: #0000FF;">Close</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>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>The only references you need are : System and System.Web.Extensions</p>
]]></content:encoded>
			<wfw:commentRss>http://florent.clairambault.fr/access-your-google-latitude-position-from-a-net-app/feed</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<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="p7998"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p799code8"><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="p7999"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code" id="p799code9"><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="p79910"><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="p799code10"><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="p79911"><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="p799code11"><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="p79912"><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="p799code12"><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/18 queries in 0.006 seconds using disk: basic
Object Caching 608/629 objects using disk: basic

Served from: florent.clairambault.fr @ 2012-02-07 10:25:19 -->
