<?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>MIKE &#187; C#.NET</title>
	<atom:link href="http://helios.ca/category/development/csharp/feed/" rel="self" type="application/rss+xml" />
	<link>http://helios.ca</link>
	<description>Just another developer blog</description>
	<lastBuildDate>Thu, 10 Jun 2010 15:02:37 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>ASP.NET MVC 2 &#8211; Linking between Areas</title>
		<link>http://helios.ca/2010/06/10/asp-net-mvc-2-linking-between-areas/</link>
		<comments>http://helios.ca/2010/06/10/asp-net-mvc-2-linking-between-areas/#comments</comments>
		<pubDate>Thu, 10 Jun 2010 15:02:37 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#.NET]]></category>
		<category><![CDATA[MVC]]></category>

		<guid isPermaLink="false">http://helios.ca/?p=267</guid>
		<description><![CDATA[If you&#8217;ve been playing with MVC 2 you might be wondering how to make ActionLinks between areas. I know it took me a good half hour to figure out! Here it is: Html.ActionLink("Display Text", "Action", "Controller", new { area = "Area" }, null); I hope it helps someone!]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;ve been playing with MVC 2 you might be wondering how to make ActionLinks between areas. I know it took me a good half hour to figure out!</p>
<p>Here it is:</p>
<pre class="csharp" name="code">
Html.ActionLink("Display Text", "Action", "Controller", new { area = "Area" }, null);
</pre>
<p>I hope it helps someone!</p>
]]></content:encoded>
			<wfw:commentRss>http://helios.ca/2010/06/10/asp-net-mvc-2-linking-between-areas/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ASP.NET MVC Cascading DropDownList with jQuery</title>
		<link>http://helios.ca/2009/05/30/aspnet-mvc-cascading-dropdownlist-with-jquery/</link>
		<comments>http://helios.ca/2009/05/30/aspnet-mvc-cascading-dropdownlist-with-jquery/#comments</comments>
		<pubDate>Sat, 30 May 2009 22:50:00 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#.NET]]></category>
		<category><![CDATA[Developement]]></category>
		<category><![CDATA[LINQ]]></category>
		<category><![CDATA[MVC]]></category>

		<guid isPermaLink="false">http://helios.ca/?p=64</guid>
		<description><![CDATA[Here a simple example of cascading drop down list in ASP.NET MVC with jQuery. First you need models. I chosed to do this example using a Country and State dropdown, so I&#8217;m going to build to Models (Country and State) with a little bit of fake data. Lets start with the Country Model and Fake [...]]]></description>
			<content:encoded><![CDATA[<p>Here a simple example of cascading drop down list in ASP.NET MVC with jQuery.</p>
<p>First you need models. I chosed to do this example using a Country and State dropdown, so I&#8217;m going to build to Models (Country and State) with a little bit of fake data.</p>
<p>Lets start with the Country Model and Fake Data</p>
<pre name="code" class="csharp">using System.Collections.Generic;
using System.Linq;

namespace CascadingDDLjQueryDemo.Models
{
    public class Country
    {
        public string CountryCode { get; set; }
        public string CountryName { get; set; }

        public static IQueryable<Country> GetCountries()
        {
            return new List<Country>
            {
                new Country {
                    CountryCode = "CA",
                    CountryName = "Canada"
                },
                new Country{
                    CountryCode = "US",
                    CountryName = "United-States"
                }
            }.AsQueryable();
        }
    }
}</pre>
<p>And now the State Model and Fake Data</p>
<pre name="code" class="csharp">using System.Collections.Generic;
using System.Linq;

namespace CascadingDDLjQueryDemo.Models
{
    public class State
    {
        public string CountryCode { get; set; }
        public int StateID { get; set; }
        public string StateName { get; set; }

        public static IQueryable<State> GetStates()
        {
            return new List<State>
            {
                new State
                    {
                        CountryCode = "CA",
                        StateID=1,
                        StateName = "Ontario"
                    },
                new State
                    {
                        CountryCode = "CA",
                        StateID=2,
                        StateName = "Quebec"
                    },
                new State
                    {
                        CountryCode = "CA",
                        StateID=3,
                        StateName = "Nova Scotia"
                    },
                new State
                    {
                        CountryCode = "CA",
                        StateID=4,
                        StateName = "New Brunswick"
                    },
                new State
                    {
                        CountryCode = "CA",
                        StateID=5,
                        StateName = "Manitoba"
                    },
                new State
                    {
                        CountryCode = "CA",
                        StateID=6,
                        StateName = "British Columbia"
                    },
                new State
                    {
                        CountryCode = "CA",
                        StateID=7,
                        StateName = "Prince Edward Island"
                    },
                new State
                    {
                        CountryCode = "CA",
                        StateID=8,
                        StateName = "Saskatchewan"
                    },
                new State
                    {
                        CountryCode = "CA",
                        StateID=9,
                        StateName = "Alberta"
                    },
                new State
                    {
                        CountryCode = "CA",
                        StateID=10,
                        StateName = "Newfoundland and Labrador"
                    },
                new State
                    {
                        CountryCode = "US",
                        StateID=11,
                        StateName = "New-York"
                    },
                new State
                    {
                        CountryCode = "US",
                        StateID=12,
                        StateName = "California"
                    },
                new State
                    {
                        CountryCode = "US",
                        StateID=13,
                        StateName = "Washington"
                    },
                new State
                    {
                        CountryCode = "US",
                        StateID=14,
                        StateName = "Vermont"
                    }
            }.AsQueryable();
        }
    }
}</pre>
<p>We can now add List methods in the controller. I chosed to return both Json and View so I could decide to make a page CountryList and use the same method.</p>
<pre name="code" class="csharp">using System.Linq;
using System.Web.Mvc;
using CascadingDDLjQueryDemo.Models;

namespace CascadingDDLjQueryDemo.Controllers
{
    [HandleError]
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            return View();
        }

        public ActionResult CountryList()
        {
            IQueryable countries =
                Country.GetCountries();

            if(HttpContext.Request.IsAjaxRequest())
                return Json(new SelectList(
                                countries,
                                "CountryCode",
                                "CountryName")
                            );

            return View(countries);
        }

        public ActionResult StateList(string CountryCode)
        {
            IQueryable states = State.GetStates()
                .Where(x =&gt; x.CountryCode == CountryCode);

            if (HttpContext.Request.IsAjaxRequest())
                return Json(new SelectList(
                                states,
                                "StateID",
                                "StateName")
                            );

            return View(states);
        }
    }
}</pre>
<p>And now we require Routes to access this data</p>
<pre name="code" class="csharp">using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

namespace CascadingDDLjQueryDemo
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode,
    // visit http://go.microsoft.com/?LinkId=9394801

    public class MvcApplication : System.Web.HttpApplication
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                "StatesList",
                "Home/States/List/{CountryCode}",
                new { controller = "Home", action = "StateList", CountryCode = "" }
            );

            routes.MapRoute(
                "CountriesList",
                "Home/Countries/List",
                new { controller = "Home", action = "CountryList" }
            );

            routes.MapRoute(
                "Default",
                "{controller}/{action}/{id}",
                new { controller = "Home", action = "Index", id = "" }
            );

        }

        protected void Application_Start()
        {
            RegisterRoutes(RouteTable.Routes);
        }
    }
}</pre>
<p>The Javavascript</p>
<pre name="code" class="javascript">$(function() {
        $.getJSON("/Home/Countries/List", function(data) {
            var items = "
<option>---------------------</option>

";
            $.each(data, function(i, country) {
                items += "
<option value='"+country.Value+"'>" + country.Text + "</option>

";
            });
            $("#Countries").html(items);
        });

        $("#Countries").change(function() {
            $.getJSON("/Home/States/List/" + $("#Countries &gt; option:selected").attr("value"), function(data) {
                var items = "
<option>---------------------</option>

";
                $.each(data, function(i, state) {
                    items += "
<option value='"+state.Value+"'>" + state.Text + "</option>

";
                });
                $("#States").html(items);
            });
        });
    });</pre>
<p>And finally, the Index View.</p>
<pre name="code" class="xhtml">
<h2>ASP.NET MVC Cascading DropDownList using jQuery</h2>

<label for="Countries">Countries</label>
<select id="Countries" name="Countries"></select>

        <label for="States">States</label>
<select id="States" name="States"></select>
</pre>
<p>You can find the <a href="http://www.helios.ca/wp-content/uploads/2009/05/CascadingDropDownListJquery.zip">source code here.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://helios.ca/2009/05/30/aspnet-mvc-cascading-dropdownlist-with-jquery/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>ASP.NET MVC Action Filter &#8211; Ajax Only Attribute</title>
		<link>http://helios.ca/2009/05/27/aspnet-mvc-action-filter-ajax-only-attribute/</link>
		<comments>http://helios.ca/2009/05/27/aspnet-mvc-action-filter-ajax-only-attribute/#comments</comments>
		<pubDate>Wed, 27 May 2009 19:03:02 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#.NET]]></category>
		<category><![CDATA[Developement]]></category>
		<category><![CDATA[MVC]]></category>

		<guid isPermaLink="false">http://helios.ca/?p=101</guid>
		<description><![CDATA[The website I&#8217;m currently working on has a lot of AJAX incorporated in it, so my controller has a few actions which are only called in AJAX. At first I was using HttpContext.Request.IsAjaxRequest() within my action to control if the request was indeed an Ajax one, but I didn&#8217;t like the fact that I needed [...]]]></description>
			<content:encoded><![CDATA[<p>The website I&#8217;m currently working on has a lot of AJAX incorporated in it, so my controller has a few actions which are only called in AJAX. At first I was using HttpContext.Request.IsAjaxRequest() within my action to control if the request was indeed an Ajax one, but I didn&#8217;t like the fact that I needed to call HttpContext in my control; it also made a lot of redundant code. That is why I decided to build an Action Filter that would do that for me.</p>
<p>Here&#8217;s the Action Filter</p>
<pre class="csharp" name="code">    public class AjaxOnlyAttribute : ActionFilterAttribute
    {
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            if(!filterContext.HttpContext.Request.IsAjaxRequest())
                filterContext.HttpContext.Response.Redirect("/error/404");
        }

        public override void OnActionExecuted(ActionExecutedContext filterContext)
        {

        }
    }</pre>
<p>And an implementation example</p>
<pre class="csharp" name="code">    [AjaxOnly]
    public ActionResult AjaxActionMethod()
    {
        ....
    }</pre>
<p>This might not be the best solution, but works pretty good for me so far!</p>
]]></content:encoded>
			<wfw:commentRss>http://helios.ca/2009/05/27/aspnet-mvc-action-filter-ajax-only-attribute/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>ASP.NET MVC Route Debugging</title>
		<link>http://helios.ca/2009/05/26/aspnet-mvc-route-debugging/</link>
		<comments>http://helios.ca/2009/05/26/aspnet-mvc-route-debugging/#comments</comments>
		<pubDate>Wed, 27 May 2009 00:25:47 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#.NET]]></category>
		<category><![CDATA[Developement]]></category>
		<category><![CDATA[MVC]]></category>

		<guid isPermaLink="false">http://helios.ca/?p=70</guid>
		<description><![CDATA[When working with Routes in ASP.NET MVC, you sometimes expect a route to match, but another route matches instead. There is currently no way to debug this using Visual Studio. Phil Haack, from Haacked.com, developed a small utility which displays the route data pulled from the request of the current request in the address bar.  [...]]]></description>
			<content:encoded><![CDATA[<p>When working with Routes in ASP.NET MVC, you sometimes expect a route to match, but another route matches instead. There is currently no way to debug this using Visual Studio.</p>
<p>Phil Haack, from Haacked.com, developed a small utility which displays the route data pulled from the request of the current request in the address bar.  At the bottom, it shows a list of all defined routes in your application. This allows you to see which of your routes would match the current URL.</p>
<p><img class="alignnone size-full wp-image-75" title="route-tester-windows-internet-explorer-2_3" src="http://helios.ca/wp-content/uploads/2009/05/route-tester-windows-internet-explorer-2_3.png" alt="route-tester-windows-internet-explorer-2_3" width="579" height="732" /></p>
<p>All you need to do to start debugging your routes is add Phil Haack&#8217;s assembly to your bin folder and add one simple line to your <strong>Global.asax</strong>:</p>
<pre class="csharp" name="code">protected void Application_Start(object sender, EventArgs e)
{
    RegisterRoutes(RouteTable.Routes);
    RouteDebug.RouteDebugger.
        RewriteRoutesForTesting(RouteTable.Routes);
}</pre>
<p>You can find <a href="http://haacked.com/archive/2008/03/13/url-routing-debugger.aspx">Phil&#8217;s post here</a>, along with the <a href="http://haacked.com/code/RouteDebug-Binary.zip">assembly </a>and even the <a href="http://haacked.com/code/RouteTesterDemo.zip">source code with a demonstration</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://helios.ca/2009/05/26/aspnet-mvc-route-debugging/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ASP.NET MVC Forms Authentication with Active Directory</title>
		<link>http://helios.ca/2009/05/04/aspnet-mvc-forms-authentication-with-active-directory/</link>
		<comments>http://helios.ca/2009/05/04/aspnet-mvc-forms-authentication-with-active-directory/#comments</comments>
		<pubDate>Mon, 04 May 2009 13:15:54 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Active Directory]]></category>
		<category><![CDATA[C#.NET]]></category>
		<category><![CDATA[Developement]]></category>
		<category><![CDATA[MVC]]></category>

		<guid isPermaLink="false">http://helios.ca/?p=5</guid>
		<description><![CDATA[This is a very basic example of how to integrate Active Directory Authentication using ASP.NET MVC. This is very easy and requires only about 10 minutes to accomplish. ASP.NET MVC Templates already have the required code and configuration to use the Authentication, so all we need to do is change the configuration to point to [...]]]></description>
			<content:encoded><![CDATA[<p>This is a very basic example of how to integrate Active Directory Authentication using ASP.NET MVC. This is very easy and requires only about 10 minutes to accomplish.</p>
<p>ASP.NET MVC Templates already have the required code and configuration to use the Authentication, so all we need to do is change the configuration to point to our Active Directory instead of SQL Express.</p>
<p>To do this you will need an accessible Active Directory and Visual Studio with MVC templates installed. I won&#8217;t show you how to install and configure AD here as I do not have this knowledge, yet!</p>
<ol>
<li>Create a new ASP.NET MVC Web Application<br />
<img src="http://helios.ca/wp-content/uploads/2009/05/050409-1315-aspnetmvcfo1.png" alt="" width="487" height="355" /></li>
<li>Visual Studio will ask you if you want to create a test project, I usually work in TDD so I always say yes. You should now have 2 projects in your solution.<br />
<img src="http://helios.ca/wp-content/uploads/2009/05/050409-1315-aspnetmvcfo2.png" alt="" /></li>
<li>If you open the <strong>Web.Config</strong> file and locate the <strong>&lt;connectionStrings&gt;</strong>, you will notice there is already a connection; you can remove it and add a new one for you Active Directory.<br />
<img class="alignnone size-full wp-image-13" title="4" src="http://helios.ca/wp-content/uploads/2009/05/4.png" alt="4" width="741" height="48" /></li>
<li>Now locate the tags <strong>authentication</strong>, <strong>membership</strong>, <strong>profile</strong>, <strong>roleManager</strong> and remove them (or comment out). Insert these<br />
<img class="alignnone size-full wp-image-14" title="5" src="http://helios.ca/wp-content/uploads/2009/05/5.png" alt="5" /></li>
<li>Now run the solution and try it using an existing user. You will need to use <strong>username@domain</strong> for the authentication to work.</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://helios.ca/2009/05/04/aspnet-mvc-forms-authentication-with-active-directory/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>ASP.NET MVC Forms Authentication with SqlMembershipProvider</title>
		<link>http://helios.ca/2009/04/22/aspnet-mvc-sqlmembershipprovider/</link>
		<comments>http://helios.ca/2009/04/22/aspnet-mvc-sqlmembershipprovider/#comments</comments>
		<pubDate>Thu, 23 Apr 2009 01:16:57 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#.NET]]></category>
		<category><![CDATA[Developement]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://helios.ca/?p=84</guid>
		<description><![CDATA[The ASP.NET MVC Website Template comes pre-configured to use SqlMembershipProvider which manages storage of membership information for an ASP.NET application in a SQL Server database. But before you can use this properly you will need to setup your database, which will be very easy because Microsoft shipped .NET 2.0 with a nice utility to do [...]]]></description>
			<content:encoded><![CDATA[<p>The ASP.NET MVC Website Template comes pre-configured to use SqlMembershipProvider which manages storage of membership information for an ASP.NET application in a SQL Server database.</p>
<p>But before you can use this properly you will need to setup your database, which will be very easy because Microsoft shipped .NET 2.0 with a nice utility to do it! You can find this on your computer, at this path<em> C:\Windows\Microsoft.NET\Framework\v2.0.50727\aspnet_regsql.exe</em></p>
<p><img class="alignnone size-full wp-image-89" title="1" src="http://helios.ca/wp-content/uploads/2009/05/1.jpg" alt="1" width="580" height="450" /></p>
<p>Your database should have these tables:</p>
<p><img class="alignnone size-full wp-image-90" title="2" src="http://helios.ca/wp-content/uploads/2009/05/2.jpg" alt="2" width="269" height="205" /></p>
<p>Now lets tell our ASP.NET MVC Website&#8217;s configuration where to find this database. Open the web.config and change the ApplicationServices connection string to point to your SQL Server. You should now rebuild your solution to avoid any problems in the next step!</p>
<pre class="xml" name="code">&lt;connectionStrings&gt;
    &lt;add name="ApplicationServices"
         connectionString="Data Source=localhost;
                           Initial Catalog=database;
                           Persist Security Info=True;
                           User ID=user;
                           Password=password"
         providerName="System.Data.SqlClient"
    /&gt;
&lt;/connectionStrings&gt;</pre>
<p>It&#8217;s all good and nice but now we need Users in this database otherwise it&#8217;s completly useless! So open up your ASP.NET MVC Solution in Visual Studio and go to <strong>Project » ASP.NET Configuration</strong>. This will open the ASP.NET Web Application Administration website. In the Security tab you can Add/Manage Users and Roles. For the moment, add a user so we can try the login. I&#8217;ve added user <strong>Mike</strong>.</p>
<p><img class="alignnone size-full wp-image-91" title="3" src="http://helios.ca/wp-content/uploads/2009/05/3.jpg" alt="3" width="527" height="507" /></p>
<p>You can now run your application and click on [ Log On ] at the top right corner of the page, this will redirect you the the logon form.</p>
<p><img class="alignnone size-full wp-image-92" title="4" src="http://helios.ca/wp-content/uploads/2009/05/4.jpg" alt="4" width="515" height="516" /></p>
<p>If you entered the correct credential you should be redirected to the home page of the site and you will see your name and a Log Off button instead of the Log On button.</p>
<p><img class="alignnone size-full wp-image-93" title="5" src="http://helios.ca/wp-content/uploads/2009/05/5.jpg" alt="5" width="517" height="267" /></p>
<p>Well congraticulations! You now have SqlMembershipProvider working on your website, wasn&#8217;t so hard, was it? Not a single line of code required! I&#8217;ll be posting again soon to show you how to use Roles in your applications.</p>
]]></content:encoded>
			<wfw:commentRss>http://helios.ca/2009/04/22/aspnet-mvc-sqlmembershipprovider/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
