<?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>Einar Egilsson &#187; ASP.NET</title>
	<atom:link href="http://einaregilsson.com/category/aspnet/feed/" rel="self" type="application/rss+xml" />
	<link>http://einaregilsson.com</link>
	<description>A site for my programming pet projects</description>
	<lastBuildDate>Fri, 03 Feb 2012 20:08:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Chord Image Generator</title>
		<link>http://einaregilsson.com/chord-image-generator/</link>
		<comments>http://einaregilsson.com/chord-image-generator/#comments</comments>
		<pubDate>Thu, 23 Jul 2009 15:45:33 +0000</pubDate>
		<dc:creator>einar</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Guitar]]></category>

		<guid isPermaLink="false">http://tech.einaregilsson.com/?p=260</guid>
		<description><![CDATA[One of my non-programming related hobbies is playing guitar. I&#8217;ve used a lot of chord sheets and tablature from the internet and have often wanted to be able to print it out in a nicer format than plain ASCII. Chord definitions in online tablatures are usually written something like (xx0232) (a D chord), but I [...]]]></description>
			<content:encoded><![CDATA[<p>One of my non-programming related hobbies is playing guitar. I&#8217;ve used a lot of chord sheets and tablature from the internet and have often wanted to be able to print it out in a nicer format than plain ASCII. Chord definitions in online tablatures are usually written something like (xx0232) (a D chord), but I wanted to be able to get these nice chord diagrams like they have in the guitar magazines. So, I wrote my own little online chord image generator.<br />
<span id="more-260"></span><br />
Actually what I originally planned to do was create a whole chord sheet editor online, which would accept plain text song files and convert them into nicely formatted sheets ready for printing. They would include non monospace fonts while still having the chords line up correctly with the lyrics, chord diagrams at the top and a nice header with the name and artist. But, since I don&#8217;t have that much free time and thought I&#8217;d probably never complete that project I just created the chord image generator itself. Others can then maybe use it for something like my idea.</p>
<p>After I had written the chord image generating code itself I decided to make a little test app for it, both to teach people the correct format and just to play with. That little application can be found at <a href="http://chords.einaregilsson.com/">http://chords.einaregilsson.com/</a>. The chord images can have muted and open strings, finger positions, display the beginning fret for chords higher than the first five frets and display below the image which fingers are used for which string. They can also be generated in ten different sizes.</p>
<p>Lets look at some examples. The format of an url for a chord is: </p>
<p style="padding-left:10px;">http://chords.einaregilsson.com/[chordname].png?p=[fretpositions]&#038;f=[fingers]&#038;s=[size] </p>
<p>So, for a normally fingered E chord the url would be:</p>
<table style="vertical-align:middle; border-style:none;">
<tr>
<td style="width:90px;"><img src="http://chords.einaregilsson.com/E.png?p=022100&#038;f=-231--&#038;s=2"/></td>
<td><a href="http://chords.einaregilsson.com/E.png?p=022100&#038;f=-231--&#038;s=2">http://chords.einaregilsson.com/E.png?p=022100&#038;f=-231&#8211;&#038;s=2</a>
</td>
</tr>
</table>
<p>The name is a simple string. The only thing to remember there is that if you want to use the # symbol you must encode it as %23, because otherwise the browser will not send the rest of the url to the server. If you have two chords with the same name you can differentiate them by naming for example one E5 and the other E5<sup>II</sup>. This is done by writing the name as E5_II, with an underscore before the superscript. Below is an example of a C# chord in size 5</p>
<table style="vertical-align:middle; border-style:none;">
<tr>
<td style="width:90px;"><img src="http://chords.einaregilsson.com/C%23.png?p=x4666x&#038;f=-1333-&#038;s=5"/></td>
<td><a href="http://chords.einaregilsson.com/C%23.png?p=x4666x&#038;f=-1333-&#038;s=5">http://chords.einaregilsson.com/C%23.png?p=x4666x&#038;f=-1333-&#038;s=5</a>
</td>
</tr>
</table>
<p>The fret positions run EAGDBE, use X for muted strings, 0 for open strings and other numbers for fret positions. If you are writing a chord that uses fret positions on and over the 10th fret you must write all the positions with a dash between them. A D bar chord on the 10th fret would then be written as </p>
<table style="vertical-align:middle; border-style:none;">
<tr>
<td style="width:90px;"><img src="http://chords.einaregilsson.com/D.png?p=10-12-12-11-10-10&#038;f=134211" /></td>
<td><a href="http://chords.einaregilsson.com/D.png?p=10-12-12-11-10-10&#038;f=134211">http://chords.einaregilsson.com/D.png?p=10-12-12-11-10-10&#038;f=134211</a>
</td>
</tr>
</table>
<p>The fingering positions also run EAGDBE. Use T for thumb, 1 for index finger, 2 for middle finger, 3 for ring finger and 4 for pinky. Use a dash, -, when no finger is on a particular string. Bar chords are inferred, if you write that you are using the same finger for different strings on the same fret, then a line will be drawn through them to indicate a barred chord. An example of that is the D chord above.</p>
<p>The size is just a number from 1-10. I like size 2 the best myself, and that is the default.</p>
<p>You can cut as much off the back of the url as you want. That is, you can skip the size, fingering positions and even fret positions, and they will use defaults instead. Default size is 2, default fingerings mean that no fingerings are written, and default fret positions are none. So, for example the following four urls are all legal (although the last one is not really a D chord since it contains no fret positions):</p>
<table style="vertical-align:middle; border-style:none;">
<tr>
<td style="width:90px;"><img src="http://chords.einaregilsson.com/D.png?p=xx0232&#038;f=---132&#038;s=2"/></td>
<td><a href="http://chords.einaregilsson.com/D.png?p=xx0232&#038;f=---132&#038;s=2">http://chords.einaregilsson.com/D.png?p=xx0232&#038;f=&#8212;132&#038;s=2</a>
</td>
</tr>
<tr>
<td style="width:90px;"><img src="http://chords.einaregilsson.com/D.png?p=xx0232&#038;f=---132"/></td>
<td><a href="http://chords.einaregilsson.com/D.png?p=xx0232&#038;f=---132">http://chords.einaregilsson.com/D.png?p=xx0232&#038;f=&#8212;132</a></td>
</tr>
<tr>
<td style="width:90px;"><img src="http://chords.einaregilsson.com/D.png?p=xx0232"/></td>
<td><a href="http://chords.einaregilsson.com/D.png?p=xx0232">http://chords.einaregilsson.com/D.png?p=xx0232</a></td>
</tr>
<tr>
<td style="width:90px;"><img src="http://chords.einaregilsson.com/D.png"/></td>
<td><a href="http://chords.einaregilsson.com/D.png">http://chords.einaregilsson.com/D.png</a></td>
</tr>
</table>
<p>You are free to link to images directly on http://chords.einaregilsson.com from your own website, although I make no guarantees about uptime, performance or anything like that. The images are cached for a week, so loading time should be fast after the first time.</p>
<p>The code for this was written in C# and is licensed under the GPL. The main class is called ChordBoxImage and it can save the generated image in a variety of formats to any output stream. The code for the image generator as well as the little test web site is available on <a href="https://github.com/einaregilsson/ChordImageGenerator">GitHub</a>. Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://einaregilsson.com/chord-image-generator/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Extensionless urls in ASP.NET MVC on IIS 6</title>
		<link>http://einaregilsson.com/extensionless-urls-in-asp-net-mvc-on-iis-6/</link>
		<comments>http://einaregilsson.com/extensionless-urls-in-asp-net-mvc-on-iis-6/#comments</comments>
		<pubDate>Thu, 06 Nov 2008 18:45:52 +0000</pubDate>
		<dc:creator>einar</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[Tips & Tricks]]></category>

		<guid isPermaLink="false">http://tech.einaregilsson.com/?p=129</guid>
		<description><![CDATA[I recently started playing around with ASP.NET MVC to build a small website. I&#8217;m pretty impressed, I like working with MVC a lot better than the web forms model. One thing that ASP.NET MVC offers is to have &#8220;pretty urls&#8221; similar to frameworks like Ruby on Rails or Django, that is, instead of urls that [...]]]></description>
			<content:encoded><![CDATA[<p>I recently started playing around with <a href="http://asp.net/mvc">ASP.NET MVC</a> to build a small website. I&#8217;m pretty impressed, I like working with MVC a lot better than the web forms model. One thing that ASP.NET MVC offers is to have &#8220;pretty urls&#8221; similar to frameworks like <a href="http://rubyonrails.org">Ruby on Rails</a> or <a href="http://djangoproject.com">Django</a>, that is, instead of urls that look like <strong>http://example.com/index.aspx?car=Ford&#038;year=1990</strong> you get urls like <strong>http://example.com/cars/Ford/1990</strong>. This works flawlessly in Visual Studio using the development webserver but there can be some complications when deploying to IIS. The new IIS 7 has support for this built in when using integrated mode, however my webhost is still on IIS 6 and there are problems there. Essentially there are two ways that can be used with IIS 6. The first way is to map all requests to the ASP.NET engine, even ones for images, css etc. That works but has some performance implications. The other way is to use a file extension in all urls, so our example url might have to be something like <strong>http://example.com/cars.aspx/Ford/1990/</strong>. That&#8217;s not horrible but not the way I want it either. So, I came up with another way. <span id="more-129"></span></p>
<p>I wrote a blog post a while ago about how to get <a href="/2007/07/30/pretty-wordpress-permalinks-on-iis/">pretty wordpress permalinks on IIS</a> using IIS&#8217;s 404 page, so I figured I might be able to hack something similar together for this. Just a bit about how the IIS 404 page works: when IIS doesn&#8217;t find an item for a request it will execute the 404 page with the missing page&#8217;s url as a querystring. So, if we make a request for <strong>http://example.com/doesntexist</strong> and the 404 page is <strong>/notfound.aspx</strong> then the server executes <strong>http://example.com/notfound.aspx?404;http://example.com/doesntexist</strong>. The important thing here is that IIS executes this in response to the original request, it does not redirect to this page. That means that even as we&#8217;re executing the 404 page the user still sees <strong>http://example.com/doesntexist</strong> in his browser url bar. (Note that when you set the 404 page in IIS it allows you to specify either <em>file</em> or <em>url</em>, you must choose <em>url</em>. Shared hosting webhosts typically offer just <em>url</em>, at least mine only does. Also, the 404 page you can specify in web.config is a completely different thing, that is redirected to and so is useless for this.)</p>
<p>When you create a new MVC project in Visual Studio you get a file called Default.aspx in your root directory. (Note: this whole article is about how things are in the MVC beta, they might change in other versions). In the codebehind file, Default.aspx.cs there is a page load method that does some rewriting and then executes an Mvc http handler. I set this file to be my 404 page in IIS (you might use a different file if you want it somewhere else) and then changed its Page_Load method to be like this:</p>
<pre class="brush: csharp; title: ; notranslate">
public void Page_Load(object sender, System.EventArgs e) {
    string querystring = Request.ServerVariables[&amp;amp;quot;QUERY_STRING&amp;amp;quot;];
    if (querystring.StartsWith(&amp;amp;quot;404;&amp;amp;quot;)) {
        int startPos = querystring.IndexOf('/', &amp;amp;quot;404;https://1&amp;amp;quot;.Length);
        HttpContext.Current.RewritePath(querystring.Substring(startPos));
    } else {
        HttpContext.Current.RewritePath(Request.ApplicationPath);
    }
    IHttpHandler httpHandler = new MvcHttpHandler();
    httpHandler.ProcessRequest(HttpContext.Current);
}
</pre>
<p>If we step through this a bit, first it checks if the querystring starts with 404; in that case the page is being executed as a 404 page, otherwise we do what this file previously did. Then we parse out the path from our querystring, rewrite it into our current http context and then execute the MvcHttpHandler on it. So, all requests with paths like <strong>/cars/Ford/1990</strong> will end up here where we parse the relevant bit out of them and execute them with MVC.</p>
<p>Now we have this working, but at the expense of ruining the real 404 system. Any 404 request will be routed through there, no matter what it&#8217;s for, so how can we handle real 404&#8242;s? What I did was to add a new Action to my HomeController called PageNotFound which simply looks like this:</p>
<pre class="brush: csharp; title: ; notranslate">
public ActionResult PageNotFound(string path) {
    ViewData[&amp;amp;quot;path&amp;amp;quot;] = &amp;amp;quot;/&amp;amp;quot; + path;
    Response.StatusCode = 404;
    return View();
}
</pre>
<p>and then I added a catch-all rout map at the very bottom of my route map, like so:</p>
<pre class="brush: csharp; title: ; notranslate">
routes.MapRoute(
    &amp;amp;quot;PageNotFound&amp;amp;quot;,                                      // Route name&amp;amp;lt;/span&amp;amp;gt;
    &amp;amp;quot;{*path}&amp;amp;quot;,                                           // URL with parameters&amp;amp;lt;/span&amp;amp;gt;
    new { controller = &amp;amp;quot;Home&amp;amp;quot;, action = &amp;amp;quot;PageNotFound&amp;amp;quot;}  // Parameter defaults&amp;amp;lt;/span&amp;amp;gt;
);
</pre>
<p>The <strong>{*path}</strong> means that this will match any possible path, having it at the bottom means that it will only ever execute if no other route matches => this is executed for pages that don&#8217;t exist. Then it passes the non-existent path to the controller, which sets the status code to 404 and adds the path to the ViewData, so the view can print a nice error message. One thing I had to change also was to remove the <em>Default</em> route from the route map, the one that had the url defined as <strong>{controller}/{action}/{id}</strong>. I removed it because it matched any url with three components and in the case when the components didn&#8217;t match any controller or action I got some ugly error message about missing controllers when what I really wanted was a 404 page. Instead I just explicitly state my routes now and usually don&#8217;t have the <strong>{controller}</strong> or <strong>{action}</strong> in the urls. With a bigger site this might be annoying and there are probably cleaner ways to handle it so any suggestions are welcome in the comments.</p>
<p>So that&#8217;s it. It&#8217;s all a big hack, but it does work without reducing performance by mapping everything to asp.net. I&#8217;m also not sure if the raw logs will show all those requests as 404&#8242;s or 200&#8242;s since my webhost doesn&#8217;t let me see raw lows for my subdomains, but I think they&#8217;ll be marked as 200. This has also only been tested when the site is in the root folder, I don&#8217;t know if it will work unchanged if the application is in a subfolder on the server. </p>
]]></content:encoded>
			<wfw:commentRss>http://einaregilsson.com/extensionless-urls-in-asp-net-mvc-on-iis-6/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Developing ASP.NET 1.1 in Visual Studio 2008</title>
		<link>http://einaregilsson.com/developing-aspnet-1-1-in-visual-studio-2008/</link>
		<comments>http://einaregilsson.com/developing-aspnet-1-1-in-visual-studio-2008/#comments</comments>
		<pubDate>Tue, 15 Jan 2008 10:42:01 +0000</pubDate>
		<dc:creator>einar</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://tech.einaregilsson.com/2008/01/15/developing-aspnet-11-in-visual-studio-2008/</guid>
		<description><![CDATA[I have an old ASP.NET 1.1 application that I have to maintain and which for reasons beyond my control can&#8217;t be updated to a later .net version. I hadn&#8217;t touched it in a few months but recently I had to make some small changes and realized I didn&#8217;t even have Visual Studio 2003 anymore. I [...]]]></description>
			<content:encoded><![CDATA[<p>I have an old ASP.NET 1.1 application that I have to maintain and which for reasons beyond my control can&#8217;t be updated to a later .net version. I hadn&#8217;t touched it in a few months but recently I had to make some small changes and realized I didn&#8217;t even have Visual Studio 2003 anymore. I got a new computer a few months ago and I have Visual Studio 2008 and IIS 7 on it but no VS 2003. I didn&#8217;t really want to install it, it&#8217;s pretty old at this point and not very well supported in Vista, and like most programmers I like to play with the shiny new toys, not the old obsolete ones. So I decided to try to maintain this application in Visual Studio 2008. Now, VS 2008 can target different versions of the .NET framework, but only 2.0, 3.0 and 3.5 so I was out of luck. But, thanks to a nice article I found by Jomo Fisher on compiling .NET 1.1 in VS2005 and some extra hacking I got it working pretty well. My setup was IIS 7 on Windows Vista, IIS 6 on Windows XP is pretty much the same although some of the options I point to may be located in different places. So, here&#8217;s what you need to do to develop ASP.NET 1.1 in Visual Studio 2008:<br />
<span id="more-57"></span></p>
<h4>IIS Setup</h4>
<p>Install the .NET 1.1 framework on your computer if it&#8217;s not already installed. Then start a command prompt as an administrator and then type  <strong>%WINDIR%Microsoft.NETFrameworkv1.1.4322aspnet_regiis -i</strong>. This will setup asp.net 1.1 to work with IIS 7. Next you should open up the IIS manager. Select &#8216;Application pools&#8217;, and under &#8216;Actions&#8217; on the right side of the screen select &#8216;Add application pool&#8217;. Give the new application pool a name, for instance &#8216;Asp.net 1.1&#8242;, set the framework version to &#8216;v1.1.4322&#8242; and pipeline mode to &#8216;classic&#8217;. Save the application pool.</p>
<h4>Compilation</h4>
<p>Jomo Fisher figured out a very nice way to use the C# 1.1 compiler in Visual Studio 2005 by manipulating some MSBuild target files. <a href="http://blogs.msdn.com/jomo_fisher/archive/2005/04/22/410903.aspx">Follow his instructions</a> for all the  projects in your solution. When that works, goto the project properties, goto the &#8216;Build&#8217; tab and set &#8216;Output path&#8217; to &#8216;bin&#8217;. Jomo&#8217;s method sets the output  path to &#8216;bin.Net1.1Debug&#8217; by default which won&#8217;t work for a web application, it needs the assemblies to be directly in the bin folder. Now you should be able to compile your web. If you try any .NET 2.0 specific stuff, like <span style="font-family:courier-new, monospace;">public class F&lt;T&gt;{}</span> you should get a compilation error.</p>
<h4>Debugging</h4>
<p>If you want to debug your web using the .NET 1.1 framework you can&#8217;t use the Visual Studio built-in webserver. That webserver uses the .NET 2.0 framework and even though you&#8217;ve compiled your assemblies using the C# 1.1 compiler, there&#8217;s still the aspx pages themselves that need to be compiled and we want that to happen with the C# 1.1 compiler too. Otherwise you might run into a situation where you think your web is completely working in asp.net 1.1, then you deploy to an actual 1.1 server and it&#8217;ll crash if you accidentally used some 2.0 specific stuff in your aspx files. So what we do is this: Goto project properties and the &#8216;Web&#8217; tab. Under the &#8216;Servers&#8217; section change it so that you&#8217;ve selected &#8216;Use IIS Web server&#8217;. This will show you your project url which you can change. Then press the &#8216;Create virtual directory&#8217; button. You MUST have started Visual Studio as administrator for this to work. Once you&#8217;ve done this you should go back to the IIS manager where you can now see your new virtual directory. Right click on it, press &#8216;Advanced Settings&#8217; and there, under &#8216;Behavior&#8217;, you can select which application pool to use. Change it so that it uses your brand new 1.1 application pool. </p>
<h4>Designer support</h4>
<p>I&#8217;ve got good news and bad news. The good news is that you will be able to view your pages in the designer and lay out things and it will generate the aspx file correctly for you. The bad news is that it won&#8217;t generate the codebehind member variables for you. But theres not much to it, all it means is that when you&#8217;ve added a button and given it an id of &#8216;btnDoStuff&#8217; then you should in your .aspx.cs file create a variable <span style="font-family:courier-new, monospace;">protected Button btnDoStuff;</span>. It&#8217;s a little annoying but you get used to it. It shouldn&#8217;t be too hard to write your own macro to generate members from tags, maybe I&#8217;ll do it someday (or not). Whenever you add a new page you&#8217;ll get compilation errors because of the partial classes. What I usually do is delete the .designer.cs file and remove the &#8216;partial&#8217; keyword from the main class. There&#8217;s also a using statement that references <span style="font-family:courier-new, monospace;">System.Web.UI.WebControls.WebParts</span> that you&#8217;ll have to delete.</p>
<p>I tried one approach which was to have a pre-build event that changed the name of the class in the .designer.cs file and removed the &#8216;partial&#8217; keyword. Then I made my normal class inherit from that class. That worked sometimes but sometimes members would just stop being generated so in the end I figured it wasn&#8217;t worth it and just started deleting the .designer.cs files instead. I still think creating your own macro to generate such a base class could be a good idea though.</p>
<h4>Other issues</h4>
<p>There are some other issues you might run into. Web.Config is one of them. You must remove stuff that wasn&#8217;t there in 1.1, like the &lt;connectionStrings /&gt; section.  Other than that I don&#8217;t know of any major changes, but then again my Web.Config is really simple. And then you have to make sure yourself that you don&#8217;t try to use any of the stuff that wasn&#8217;t in 1.1. That means no masterpages, generics, partial classes or any of the new webcontrols that came with 2.0. Another thing you should be aware of is that you always need to run Visual Studio as administrator for the debugging to work.</p>
<p>And that&#8217;s it. This worked for me, I don&#8217;t know if it&#8217;ll work for you. There&#8217;s some hassle involved, but for me, having some of the cool VS2008 stuff available (hello javascript intellisense) more than makes up for it.</p>
]]></content:encoded>
			<wfw:commentRss>http://einaregilsson.com/developing-aspnet-1-1-in-visual-studio-2008/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

