<?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>Martijn Boland &#187; ASP.NET MVC</title>
	<atom:link href="http://blogs.taiga.nl/martijn/category/aspnet-mvc/feed/" rel="self" type="application/rss+xml" />
	<link>http://blogs.taiga.nl/martijn</link>
	<description>New adventures in .NET</description>
	<lastBuildDate>Wed, 25 Jan 2012 22:27:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>MvcPaging 1.0.2</title>
		<link>http://blogs.taiga.nl/martijn/2011/12/07/mvcpaging-1-0-2/</link>
		<comments>http://blogs.taiga.nl/martijn/2011/12/07/mvcpaging-1-0-2/#comments</comments>
		<pubDate>Wed, 07 Dec 2011 21:57:46 +0000</pubDate>
		<dc:creator>martijn</dc:creator>
				<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[Web development]]></category>
		<category><![CDATA[Paging]]></category>
		<category><![CDATA[Razor]]></category>

		<guid isPermaLink="false">http://blogs.taiga.nl/martijn/2011/12/07/mvcpaging-1-0-2/</guid>
		<description><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://blogs.taiga.nl/martijn/2011/12/07/mvcpaging-1-0-2/' addthis:title='MvcPaging 1.0.2 '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div>A new version of the MvcPaging component is available via NuGet with the following changes: Added ItemStart and ItemEnd properties to IPagedList (Displaying items {ItemStart} &#8211; {ItemEnd}). Non-canonical url&#8217;s for page 1 (https://github.com/martijnboland/MvcPaging/issues/2). So the core library hasn’t changed much, and in all honesty, I think it’s pretty much done. Please leave a reply if <a href="http://blogs.taiga.nl/martijn/2011/12/07/mvcpaging-1-0-2/"> read more <span class="meta-nav">&#187;</span></a>]]></description>
			<content:encoded><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://blogs.taiga.nl/martijn/2011/12/07/mvcpaging-1-0-2/' addthis:title='MvcPaging 1.0.2 '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div><p>A new version of the <a href="https://github.com/martijnboland/mvcpaging">MvcPaging</a> component is available via <a href="https://nuget.org/packages/MvcPaging">NuGet</a> with the following changes:</p>
<ul>
<li>Added ItemStart and ItemEnd properties to IPagedList (Displaying items {ItemStart} &#8211; {ItemEnd}). </li>
<li>Non-canonical url&#8217;s for page 1 (<a href="https://github.com/martijnboland/MvcPaging/issues/2">https://github.com/martijnboland/MvcPaging/issues/2</a>).</li>
</ul>
<p>So the core library hasn’t changed much, and in all honesty, I think it’s pretty much done. Please leave a reply if you think otherwise.</p>
<p>What did change substantially is the sample application. It was still very much ASP.NET 1.0 with WebForms views. This is now a proper ASP.NET MVC 3 application with Razor views and the default ASP.NET MVC 4.0 template for look &amp; feel.</p>
<p>&#160;<a href="http://blogs.taiga.nl/martijn/wp-content/uploads/2011/12/Screenshot.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="Screenshot" border="0" alt="Screenshot" src="http://blogs.taiga.nl/martijn/wp-content/uploads/2011/12/Screenshot_thumb.png" width="640" height="400" /></a></p>
<p>The sample application can be found at <a href="https://github.com/martijnboland/mvcpaging">GitHub</a>. </p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.taiga.nl/martijn/2011/12/07/mvcpaging-1-0-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Custom Model Binders and Request Validation</title>
		<link>http://blogs.taiga.nl/martijn/2011/09/29/custom-model-binders-and-request-validation/</link>
		<comments>http://blogs.taiga.nl/martijn/2011/09/29/custom-model-binders-and-request-validation/#comments</comments>
		<pubDate>Thu, 29 Sep 2011 11:15:21 +0000</pubDate>
		<dc:creator>martijn</dc:creator>
				<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Validation]]></category>

		<guid isPermaLink="false">http://blogs.taiga.nl/martijn/2011/09/29/custom-model-binders-and-request-validation/</guid>
		<description><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://blogs.taiga.nl/martijn/2011/09/29/custom-model-binders-and-request-validation/' addthis:title='Custom Model Binders and Request Validation '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div>In ASP.NET MVC you can create your own model binders to control the way that models are constructed from an HTTP request. For example, if you don’t want any whitespace characters in your model, you can create a custom model binder that trims all whitespace characters when constructing&#160; a model object. You only have to <a href="http://blogs.taiga.nl/martijn/2011/09/29/custom-model-binders-and-request-validation/"> read more <span class="meta-nav">&#187;</span></a>]]></description>
			<content:encoded><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://blogs.taiga.nl/martijn/2011/09/29/custom-model-binders-and-request-validation/' addthis:title='Custom Model Binders and Request Validation '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div><p>In ASP.NET MVC you can create your own model binders to control the way that models are constructed from an HTTP request. For example, if you don’t want any whitespace characters in your model, you can create a custom model binder that trims all whitespace characters when constructing&#160; a model object. You only have to implement the <a href="http://msdn.microsoft.com/en-us/library/system.web.mvc.imodelbinder.aspx">IModelBinder</a> interface and its BindModel method in a class and register it during application startup.</p>
<h3>Getting the value from the HTTP request</h3>
<p>There are many examples online of how to build a custom model binder. In all these examples you can find a common way of getting a value from the HTTP request:</p>
<pre class="brush: csharp;">public class MyModelBinder: IModelBinder
{
    public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
    {
        var valueProviderResult = bindingContext.ValueProvider.GetValue(bindingContext.ModelName);
        if (valueProviderResult != null)
        {
            var theValue = valueProviderResult.AttemptedValue;

            // etc...
        }
    }
}</pre>
<p>The code above works nicely and you get protection for potential dangerous request values out of the box. Now let’s assume that we <em>want </em>some potential dangerous values like HTML or XML tags in our model. The recommended way is to add an [AllowHtml] attribute to the model property that may contain HTML and no validation happens for that property. Alternatively, it’s possible to add an [ValidateInput(false)] attribute to the controller action that accepts the model with HTML content, but this turns off validation for<em> </em>all model properties. </p>
<h3>A potentially dangerous Request.Form value was detected from the client</h3>
<p>Wait a minute! Didn’t we just explicitly say to allow those dangerous values? What’s happening?</p>
<p>It appears that a call to bindingContext.ValueProvider.GetValue() in the code above <em>always</em> validates the data, regardless any attributes. Digging into the ASP.NET MVC sources revealed that the DefaultModelBinder first checks&#160; if request validation is required and then calls the bindingContext.UnvalidatedValueProvider.GetValue() method with a parameter that indicates if validation is required or not. </p>
<p>Unfortunately we can’t use any of the framework code because it’s sealed, private or whatever to protect ignorant devs from doing dangerous stuff, but&#160; it’s not too difficult to create a working custom model binder that respects the AllowHtml and ValidateInput attributes:</p>
<pre class="brush: csharp;">public class MyModelBinder: IModelBinder
{
    public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
    {
        // First check if request validation is required
        var shouldPerformRequestValidation = controllerContext.Controller.ValidateRequest &amp;&amp; bindingContext.ModelMetadata.RequestValidationEnabled;

        // Get value
        var valueProviderResult = bindingContext.GetValueFromValueProvider(shouldPerformRequestValidation);
        if (valueProviderResult != null)
        {
            var theValue = valueProviderResult.AttemptedValue;

            // etc...
        }
    }
}</pre>
<p>The other required piece is a way to retrieve an unvalidated value. In this example we use an extension method for the ModelBindingContext class:</p>
<pre class="brush: csharp;">public static ValueProviderResult GetValueFromValueProvider(this ModelBindingContext bindingContext, bool performRequestValidation)
{
    var unvalidatedValueProvider = bindingContext.ValueProvider as IUnvalidatedValueProvider;
    return (unvalidatedValueProvider != null)
               ? unvalidatedValueProvider.GetValue(bindingContext.ModelName, !performRequestValidation)
               : bindingContext.ValueProvider.GetValue(bindingContext.ModelName);
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://blogs.taiga.nl/martijn/2011/09/29/custom-model-binders-and-request-validation/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>NuGet package for MVC pager</title>
		<link>http://blogs.taiga.nl/martijn/2011/05/12/nuget-package-for-mvc-pager/</link>
		<comments>http://blogs.taiga.nl/martijn/2011/05/12/nuget-package-for-mvc-pager/#comments</comments>
		<pubDate>Thu, 12 May 2011 15:15:35 +0000</pubDate>
		<dc:creator>martijn</dc:creator>
				<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[NuGet]]></category>
		<category><![CDATA[Paging]]></category>

		<guid isPermaLink="false">http://blogs.taiga.nl/martijn/2011/05/12/nuget-package-for-mvc-pager/</guid>
		<description><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://blogs.taiga.nl/martijn/2011/05/12/nuget-package-for-mvc-pager/' addthis:title='NuGet package for MVC pager '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div>It’s now possible to add the MVC pager to your own project with NuGet. Or from Visual Studio with ‘Manage NuGet Packages&#8230;’ and then search for ‘MvcPaging’. After installing, you can immediately use the Pager HtmlHelper in your views: et voilà! We also have include the IPagedList for your convenience: For more info, check out <a href="http://blogs.taiga.nl/martijn/2011/05/12/nuget-package-for-mvc-pager/"> read more <span class="meta-nav">&#187;</span></a>]]></description>
			<content:encoded><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://blogs.taiga.nl/martijn/2011/05/12/nuget-package-for-mvc-pager/' addthis:title='NuGet package for MVC pager '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div><p>It’s now possible to add the <a href="https://github.com/martijnboland/MvcPaging">MVC pager</a> to your own project with <a href="http://nuget.org/">NuGet</a>.</p>
<p><a href="http://blogs.taiga.nl/martijn/wp-content/uploads/2011/05/image4.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://blogs.taiga.nl/martijn/wp-content/uploads/2011/05/image_thumb4.png" alt="image" width="600" height="77" border="0" /></a></p>
<p>Or from Visual Studio with ‘Manage NuGet Packages&#8230;’ and then search for ‘MvcPaging’.</p>
<p>After installing, you can immediately use the Pager HtmlHelper in your views:</p>
<p><a href="http://blogs.taiga.nl/martijn/wp-content/uploads/2011/05/image5.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://blogs.taiga.nl/martijn/wp-content/uploads/2011/05/image_thumb5.png" alt="image" width="600" height="187" border="0" /></a></p>
<p>et voilà!</p>
<p><a href="http://blogs.taiga.nl/martijn/wp-content/uploads/2011/05/image6.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://blogs.taiga.nl/martijn/wp-content/uploads/2011/05/image_thumb6.png" alt="image" width="600" height="392" border="0" /></a></p>
<p>We also have include the IPagedList for your convenience:</p>
<p><a href="http://blogs.taiga.nl/martijn/wp-content/uploads/2011/05/image7.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://blogs.taiga.nl/martijn/wp-content/uploads/2011/05/image_thumb7.png" alt="image" width="600" height="331" border="0" /></a></p>
<p>For more info, check out <a href="http://blogs.taiga.nl/martijn/2008/08/27/paging-with-aspnet-mvc/">the original blogpost</a> that started it or the <a href="https://github.com/martijnboland/MvcPaging">github project page</a>.</p>
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.taiga.nl/martijn/2011/05/12/nuget-package-for-mvc-pager/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Keep your users informed with ASP.NET MVC</title>
		<link>http://blogs.taiga.nl/martijn/2011/05/03/keep-your-users-informed-with-asp-net-mvc/</link>
		<comments>http://blogs.taiga.nl/martijn/2011/05/03/keep-your-users-informed-with-asp-net-mvc/#comments</comments>
		<pubDate>Tue, 03 May 2011 14:09:50 +0000</pubDate>
		<dc:creator>martijn</dc:creator>
				<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[Web development]]></category>
		<category><![CDATA[Notification]]></category>

		<guid isPermaLink="false">http://blogs.taiga.nl/martijn/?p=161</guid>
		<description><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://blogs.taiga.nl/martijn/2011/05/03/keep-your-users-informed-with-asp-net-mvc/' addthis:title='Keep your users informed with ASP.NET MVC '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div>In almost every application, feedback from the application to the user via notification messages is required. For some strange reason, we don’t have a standard way in .NET web applications for dealing with this kind of messages and I find myself hacking some half-baked solutions over and over again. Starting from today, this must end! <a href="http://blogs.taiga.nl/martijn/2011/05/03/keep-your-users-informed-with-asp-net-mvc/"> read more <span class="meta-nav">&#187;</span></a>]]></description>
			<content:encoded><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://blogs.taiga.nl/martijn/2011/05/03/keep-your-users-informed-with-asp-net-mvc/' addthis:title='Keep your users informed with ASP.NET MVC '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div><p>In almost every application, feedback from the application to the user via notification messages is required. </p>
<p><a href="http://blogs.taiga.nl/martijn/wp-content/uploads/2011/05/success.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="success" border="0" alt="success" src="http://blogs.taiga.nl/martijn/wp-content/uploads/2011/05/success_thumb.png" width="513" height="52" /></a></p>
<p>For some strange reason, we don’t have a standard way in .NET web applications for dealing with this kind of messages and I find myself hacking some half-baked solutions over and over again. Starting from today, this must end! In this post we’re going to find a solution for ASP.NET MVC 3.</p>
<h3>One single way to display messages</h3>
<p>This is the one and only requirement: </p>
<blockquote><p>In every scenario I want to be able to call ShowMessage() from my controller action and the message appears on the screen.</p>
</blockquote>
<h3>ShowMessage extension method</h3>
<p>To have a ShowMessage method in every controller action, we could implement it in a base controller class or create an extension method. Let’s try an extension method:</p>
<pre class="brush: csharp;">public static void ShowMessage(this Controller controller, MessageType messageType, string message, bool showAfterRedirect = false)
{
    var messageTypeKey = messageType.ToString();
    if (showAfterRedirect)
    {
        controller.TempData[messageTypeKey] = message;
    }
    else
    {
        controller.ViewData[messageTypeKey] = message;
    }
}</pre>
<p>All this method does is take a message type enum (Success, Warning or Error) and a message and store it in either ViewData or TempData, depending on the flag ‘showAfterRedirect’. TempData is for <a href="http://en.wikipedia.org/wiki/Post/Redirect/Get">Post-Redirect-Get</a> situations.</p>
<p>We can now call ShowMessage(). With this solution it’s only possible to store one type of message per request, but that should be enough (even more than one message is already troublesome).</p>
<h3>RenderMessages HTML Helper</h3>
<p>Creating messages is one thing, but what about displaying them? It’s also easy. Enter the RenderMessages() HTML helper:</p>
<pre class="brush: csharp;">/// &lt;summary&gt;
/// Render all messages that have been set during execution of the controller action.
/// &lt;/summary&gt;
/// &lt;param name=&quot;htmlHelper&quot;&gt;&lt;/param&gt;
/// &lt;returns&gt;&lt;/returns&gt;
public static HtmlString RenderMessages(this HtmlHelper htmlHelper)
{
    var messages = String.Empty;
    foreach (var messageType in Enum.GetNames(typeof(MessageType)))
    {
        var message = htmlHelper.ViewContext.ViewData.ContainsKey(messageType)
                        ? htmlHelper.ViewContext.ViewData[messageType]
                        : htmlHelper.ViewContext.TempData.ContainsKey(messageType)
                            ? htmlHelper.ViewContext.TempData[messageType]
                            : null;
        if (message != null)
        {
            var messageBoxBuilder = new TagBuilder(&quot;div&quot;);
            messageBoxBuilder.AddCssClass(String.Format(&quot;messagebox {0}&quot;, messageType.ToLowerInvariant()));
            messageBoxBuilder.SetInnerText(message.ToString());
            messages += messageBoxBuilder.ToString();
        }
    }
    return MvcHtmlString.Create(messages);
}</pre>
<p>It iterates through all possible message types, tries to find a message in either ViewData or TempData and creates a div with the message in it.<br />
  <br />Put the helper in the Layout page, add some css classes (.messagebox, .succes, .warning and .error) and we’re all set.</p>
<h3>What about AJAX?</h3>
<p>Now this is getting tricky. In our AJAX actions, we can still call ShowMessage(), but how should the message be displayed if we only return some JSON data or a partial view? One solution would be to wrap all AJAX results in a special JSON view result with the notification messages and the original result embedded. Drawback is that we have quite some work to do on the client-side to handle all this.</p>
<h3>HTTP headers to the rescue</h3>
<p>I discovered a very nice solution on StackOverflow: <a href="http://stackoverflow.com/questions/366311/how-do-you-handle-rails-flash-with-ajax-requests">use custom HTTP headers to store a message</a>. With the help of a global action filter we can check if there are messages in the ViewData dictionary and when the request was an AJAX request, copy the messages to a custom HTTP header.</p>
<pre class="brush: csharp;">/// &lt;summary&gt;
/// If we're dealing with ajax requests, any message that is in the view data goes to
/// the http header.
/// &lt;/summary&gt;
public class AjaxMessagesFilter : ActionFilterAttribute
{
    public override void OnActionExecuted(ActionExecutedContext filterContext)
    {
        if (filterContext.HttpContext.Request.IsAjaxRequest())
        {
            var viewData = filterContext.Controller.ViewData;
            var response = filterContext.HttpContext.Response;

            foreach (var messageType in Enum.GetNames(typeof(MessageType)))
            {
                var message = viewData.ContainsKey(messageType)
                                ? viewData[messageType]
                                : null;
                if (message != null) // We store only one message in the http header. First message that comes wins.
                {
                    response.AddHeader(&quot;X-Message-Type&quot;, messageType);
                    response.AddHeader(&quot;X-Message&quot;, message.ToString());
                    return;
                }
            }
        }
    }
}</pre>
<p><a href="http://blogs.taiga.nl/martijn/wp-content/uploads/2011/05/x-message.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="x-message" border="0" alt="x-message" src="http://blogs.taiga.nl/martijn/wp-content/uploads/2011/05/x-message_thumb.png" width="704" height="304" /></a></p>
<p>Finally the message in the HTTP headers are displayed with a little bit of jQuery:</p>
<pre class="brush: js;">$(document).ready(function () {
    handleAjaxMessages();
});

function handleAjaxMessages() {
    $(document).ajaxSuccess(function (event, request) {
        checkAndHandleMessageFromHeader(request);
    }).ajaxError(function (event, request) {
        displayMessage(request.responseText, &quot;error&quot;);
    });
}

function checkAndHandleMessageFromHeader(request) {
    var msg = request.getResponseHeader('X-Message');
    if (msg) {
        displayMessage(msg, request.getResponseHeader('X-Message-Type'));
    }
}

function displayMessage(message, messageType) {
    $(&quot;#messagewrapper&quot;).html('&lt;div class=&quot;messagebox ' + messageType.toLowerCase() + '&quot;&gt;&lt;/div&gt;');
    $(&quot;#messagewrapper .messagebox&quot;).text(message);
}</pre>
<h3>Demo</h3>
<p>For a closer look <a href="http://demo.taiga.nl/notification/" target="_blank">check out the live demo</a> or download the VS2010 solution from <a href="https://github.com/martijnboland/MvcNotification">GitHub</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.taiga.nl/martijn/2011/05/03/keep-your-users-informed-with-asp-net-mvc/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>MVC Pager update: now with AJAX support</title>
		<link>http://blogs.taiga.nl/martijn/2011/03/23/mvc-pager-update-now-with-ajax-support/</link>
		<comments>http://blogs.taiga.nl/martijn/2011/03/23/mvc-pager-update-now-with-ajax-support/#comments</comments>
		<pubDate>Wed, 23 Mar 2011 13:26:59 +0000</pubDate>
		<dc:creator>martijn</dc:creator>
				<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[Paging]]></category>

		<guid isPermaLink="false">http://blogs.taiga.nl/martijn/2011/03/23/mvc-pager-update-now-with-ajax-support/</guid>
		<description><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://blogs.taiga.nl/martijn/2011/03/23/mvc-pager-update-now-with-ajax-support/' addthis:title='MVC Pager update: now with AJAX support '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div>The MVC pager now has support for AJAX scenario’s, thanks to Bart Lenaerts. This was my first GitHub pull request and everything went pretty smoothly. Check out the demo application for an example. Visit the GitHub project page to download the solution.]]></description>
			<content:encoded><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://blogs.taiga.nl/martijn/2011/03/23/mvc-pager-update-now-with-ajax-support/' addthis:title='MVC Pager update: now with AJAX support '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div><p>The <a href="http://blogs.taiga.nl/martijn/2008/08/27/paging-with-aspnet-mvc/">MVC pager</a> now has support for AJAX scenario’s, thanks to <a href="https://github.com/blenaerts">Bart Lenaerts</a>. This was my first <a href="https://github.com">GitHub</a> pull request and everything went pretty smoothly.</p>
<p>Check out the demo application for an example. Visit the <a href="https://github.com/martijnboland/MvcPaging">GitHub project</a> page to download the solution.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.taiga.nl/martijn/2011/03/23/mvc-pager-update-now-with-ajax-support/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MVC Pager update</title>
		<link>http://blogs.taiga.nl/martijn/2011/02/11/mvc-pager-update/</link>
		<comments>http://blogs.taiga.nl/martijn/2011/02/11/mvc-pager-update/#comments</comments>
		<pubDate>Fri, 11 Feb 2011 12:16:19 +0000</pubDate>
		<dc:creator>martijn</dc:creator>
				<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[Paging]]></category>

		<guid isPermaLink="false">http://blogs.taiga.nl/martijn/2011/02/11/mvc-pager-update/</guid>
		<description><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://blogs.taiga.nl/martijn/2011/02/11/mvc-pager-update/' addthis:title='MVC Pager update '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div>Just a short message to let you know that the MVC Pager demo is upgraded to ASP.NET MVC3 and VS 2010. Get it at https://github.com/martijnboland/MvcPaging.]]></description>
			<content:encoded><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://blogs.taiga.nl/martijn/2011/02/11/mvc-pager-update/' addthis:title='MVC Pager update '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div><p>Just a short message to let you know that the <a href="http://blogs.taiga.nl/martijn/2008/08/27/paging-with-aspnet-mvc/">MVC Pager demo</a> is upgraded to ASP.NET MVC3 and VS 2010. Get it at <a title="https://github.com/martijnboland/MvcPaging" href="https://github.com/martijnboland/MvcPaging">https://github.com/martijnboland/MvcPaging</a>. </p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.taiga.nl/martijn/2011/02/11/mvc-pager-update/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Raven DB ASP.NET Membership Provider</title>
		<link>http://blogs.taiga.nl/martijn/2010/11/25/raven-db-asp-net-membership-provider/</link>
		<comments>http://blogs.taiga.nl/martijn/2010/11/25/raven-db-asp-net-membership-provider/#comments</comments>
		<pubDate>Thu, 25 Nov 2010 13:54:45 +0000</pubDate>
		<dc:creator>martijn</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[Membership]]></category>
		<category><![CDATA[NoSQL]]></category>
		<category><![CDATA[RavenDB]]></category>

		<guid isPermaLink="false">http://blogs.taiga.nl/martijn/2010/11/25/raven-db-asp-net-membership-provider/</guid>
		<description><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://blogs.taiga.nl/martijn/2010/11/25/raven-db-asp-net-membership-provider/' addthis:title='Raven DB ASP.NET Membership Provider '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div>During the last year I’ve been looking at various NoSQL databases. I’m particularly interested in the flexibility (no fixed schema) and I don’t care that much for scalability that some of these databases provide, therefore I focused on document databases like CouchDB, MongoDB and Raven DB. After some reading, I decided it was time for <a href="http://blogs.taiga.nl/martijn/2010/11/25/raven-db-asp-net-membership-provider/"> read more <span class="meta-nav">&#187;</span></a>]]></description>
			<content:encoded><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://blogs.taiga.nl/martijn/2010/11/25/raven-db-asp-net-membership-provider/' addthis:title='Raven DB ASP.NET Membership Provider '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div><p>During the last year I’ve been looking at various <a href="http://en.wikipedia.org/wiki/NoSQL">NoSQL</a> databases. I’m particularly interested in the flexibility (no fixed schema) and I don’t care that much for scalability that some of these databases provide, therefore I focused on document databases like <a href="http://couchdb.apache.org/">CouchDB</a>, <a href="http://www.mongodb.org/">MongoDB</a> and <a href="http://ravendb.net/">Raven DB</a>.</p>
<p>After some reading, I decided it was time for an experiment and took Raven DB to create an ASP.NET membership provider. The main reason I chose Raven DB is that you can run it embedded in your .NET application (for example in ~/App_Data) without a separate server and it’s even possible to run the entire database in-memory, which is ideal for tests.</p>
<p>The result of the experiment can be found at <a title="https://github.com/martijnboland/RavenDBMembership" href="https://github.com/martijnboland/RavenDBMembership">https://github.com/martijnboland/RavenDBMembership</a>. It’s a VS 2010 solution with the membership provider, some integration tests and an ASP.NET MVC 3 sample app. You can also directly <a href="https://github.com/martijnboland/RavenDBMembership/zipball/master">download it from here</a>.</p>
<p><em>Disclaimer:</em></p>
<p><em>I’m not sure that creating a Membership provider was the right thing to do to experience NoSQL. Sure, the provider works, but the Membership API forces you into a direction that isn’t necessarily suitable for document databases and there might be some NoSQL anti-patterns here and there in the code</em></p>
<p><em>Oh, and the ASP.NET MVC sample app extends the Membership mess that comes with the default MVC project template. Don’t take this as some best practices example.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.taiga.nl/martijn/2010/11/25/raven-db-asp-net-membership-provider/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Paging demo for ASP.NET MVC 2</title>
		<link>http://blogs.taiga.nl/martijn/2010/01/27/paging-demo-for-asp-net-mvc-2/</link>
		<comments>http://blogs.taiga.nl/martijn/2010/01/27/paging-demo-for-asp-net-mvc-2/#comments</comments>
		<pubDate>Wed, 27 Jan 2010 18:27:58 +0000</pubDate>
		<dc:creator>martijn</dc:creator>
				<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[Area]]></category>
		<category><![CDATA[Paging]]></category>

		<guid isPermaLink="false">http://blogs.taiga.nl/martijn/2010/01/27/paging-demo-for-asp-net-mvc-2/</guid>
		<description><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://blogs.taiga.nl/martijn/2010/01/27/paging-demo-for-asp-net-mvc-2/' addthis:title='Paging demo for ASP.NET MVC 2 '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div>During work, I discovered that the pager that I created a while ago didn’t work properly when using ASP.NET MVC2 area’s. The links that were generated didn’t count for the current area that the controller and views were in, resulting in wrong urls. Luckily the ASP.NET MVC team also ran into this issue and created <a href="http://blogs.taiga.nl/martijn/2010/01/27/paging-demo-for-asp-net-mvc-2/"> read more <span class="meta-nav">&#187;</span></a>]]></description>
			<content:encoded><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://blogs.taiga.nl/martijn/2010/01/27/paging-demo-for-asp-net-mvc-2/' addthis:title='Paging demo for ASP.NET MVC 2 '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div><p>During work, I discovered that the <a href="http://blogs.taiga.nl/martijn/2008/08/27/paging-with-aspnet-mvc/" target="_blank">pager that I created a while ago</a> didn’t work properly when using ASP.NET MVC2 area’s. The links that were generated didn’t count for the current area that the controller and views were in, resulting in wrong urls. Luckily the ASP.NET MVC team also ran into this issue and created an GetVirtualPathForArea() extension method on RouteCollection. Calling this one, instead of GetVirtualPath() made things work properly in area’s.</p>
<p>You can get the code for ASP.NET MVC 2 at <a title="http://github.com/martijnboland/MvcPaging/tree/mvc2" href="http://github.com/martijnboland/MvcPaging/tree/mvc2">http://github.com/martijnboland/MvcPaging/tree/mvc2</a> (mvc2 branch of the MvcPaging repository).</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.taiga.nl/martijn/2010/01/27/paging-demo-for-asp-net-mvc-2/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Considering ASP.NET MVC UI controls? Learn HTML and Javascript!</title>
		<link>http://blogs.taiga.nl/martijn/2009/08/13/considering-asp-net-mvc-ui-controls-learn-html-and-javascript/</link>
		<comments>http://blogs.taiga.nl/martijn/2009/08/13/considering-asp-net-mvc-ui-controls-learn-html-and-javascript/#comments</comments>
		<pubDate>Thu, 13 Aug 2009 09:31:16 +0000</pubDate>
		<dc:creator>martijn</dc:creator>
				<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[Web development]]></category>
		<category><![CDATA[Components]]></category>
		<category><![CDATA[Web Standards]]></category>
		<category><![CDATA[WebForms]]></category>

		<guid isPermaLink="false">http://blogs.taiga.nl/martijn/2009/08/13/considering-asp-net-mvc-ui-controls-learn-html-and-javascript/</guid>
		<description><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://blogs.taiga.nl/martijn/2009/08/13/considering-asp-net-mvc-ui-controls-learn-html-and-javascript/' addthis:title='Considering ASP.NET MVC UI controls? Learn HTML and Javascript! '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div>Warning: highly subjective content ahead. In the recent weeks we’ve seen several control vendors come up with toolkits that target ASP.NET MVC. Personally, I don’t see anything that might make me starting to consider picking one of these toolkits to speed up development. Why on earth would I prefer a wrapper around jQuery UI or <a href="http://blogs.taiga.nl/martijn/2009/08/13/considering-asp-net-mvc-ui-controls-learn-html-and-javascript/"> read more <span class="meta-nav">&#187;</span></a>]]></description>
			<content:encoded><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://blogs.taiga.nl/martijn/2009/08/13/considering-asp-net-mvc-ui-controls-learn-html-and-javascript/' addthis:title='Considering ASP.NET MVC UI controls? Learn HTML and Javascript! '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div><p>Warning: highly subjective content ahead.</p>
<p>In the recent weeks we’ve seen <a href="http://www.telerik.com/products/aspnet-mvc.aspx" target="_blank">several</a> <a href="http://mvc.devexpress.com/" target="_blank">control</a> <a href="http://www.syncfusion.com/products/aspnet-mvc" target="_blank">vendors</a> come up with toolkits that target ASP.NET MVC. Personally, I don’t see anything that might make me starting to consider picking one of these toolkits to speed up development. Why on earth would I prefer a wrapper around jQuery UI or shoehorning existing WebForms controls in MVC views?</p>
<p>The beauty of ASP.NET MVC is that it embraces the web as it is and this automatically involves HTML, CSS and Javascript. Don’t be afraid for that. The combination can be so powerful! Why aren’t there any large component vendors for PHP, Rails, Django etc? Isn’t it probably possible that these components are not required to do proper web development?</p>
<p>The control vendors seem to be targeting people who come from a Windows background that don’t want to learn HTML and Javascript, but from my experiences I can say that those people should really stick to WebForms.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.taiga.nl/martijn/2009/08/13/considering-asp-net-mvc-ui-controls-learn-html-and-javascript/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>ASP.NET WebForms and MVC together in one project</title>
		<link>http://blogs.taiga.nl/martijn/2009/06/03/aspnet-webforms-and-mvc-together-in-one-project/</link>
		<comments>http://blogs.taiga.nl/martijn/2009/06/03/aspnet-webforms-and-mvc-together-in-one-project/#comments</comments>
		<pubDate>Wed, 03 Jun 2009 21:40:54 +0000</pubDate>
		<dc:creator>martijn</dc:creator>
				<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[Area]]></category>
		<category><![CDATA[Sample]]></category>
		<category><![CDATA[WebForms]]></category>

		<guid isPermaLink="false">http://blogs.taiga.nl/martijn/2009/06/03/aspnet-webforms-and-mvc-together-in-one-project/</guid>
		<description><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://blogs.taiga.nl/martijn/2009/06/03/aspnet-webforms-and-mvc-together-in-one-project/' addthis:title='ASP.NET WebForms and MVC together in one project '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div>This post briefly describes a solution to mix ASP.NET WebForms and MVC in one project. You can download a sample project that might be more useful than my ramblings. Download the sample here, unzip, open with VS 2008 SP1 and hit F5. There are lots of ‘legacy’ ASP.NET WebForms applications out there in the wild. <a href="http://blogs.taiga.nl/martijn/2009/06/03/aspnet-webforms-and-mvc-together-in-one-project/"> read more <span class="meta-nav">&#187;</span></a>]]></description>
			<content:encoded><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://blogs.taiga.nl/martijn/2009/06/03/aspnet-webforms-and-mvc-together-in-one-project/' addthis:title='ASP.NET WebForms and MVC together in one project '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div><p><em>This post briefly describes a solution to mix ASP.NET WebForms and MVC in one project. You can download a sample project that might be more useful than my ramblings. <a href="http://blogs.taiga.nl/martijn/wp-content/uploads/WebFormsMVCDemo.zip" target="_blank">Download the sample here</a>, unzip, open with VS 2008 SP1 and hit F5.</em></p>
<p>There are lots of ‘legacy’ ASP.NET WebForms applications out there in the wild. What if you want to create new functionality or rebuild an existing part with ASP.NET MVC, but you can’t (or won’t) create a separate new project?</p>
<p>The simple solution is to add the default MVC folders (Content, Controlllers, Scripts, Views etc.) to the root of the web project, add references to the MVC binaries, modify web.config and add the MVC GUID to the ProjectTypeGuids in the project file. A major drawback however is that it pollutes the root of your carefully structured application. This post will show you how you can logically separate the new MVC pieces from the existing WebForms app in a single project.</p>
<h3>Isolate the MVC bits</h3>
<p><img title="webforms-mvc-solution" style="border-right: 0px; border-top: 0px; display: inline; margin-left: 0px; border-left: 0px; margin-right: 0px; border-bottom: 0px" height="449" alt="webforms-mvc-solution" src="http://blogs.taiga.nl/martijn/wp-content/uploads/2009/06/webformsmvcsolution3.png" width="297" align="right" border="0" />&#160; A simple requirement: I want that all my MVC folders reside in the folder /MyMvcApp <em>and </em>I also want that all urls of the MVC app start with /mymvcapp. No interference with my old WebForms app please.</p>
<h3></h3>
<h3>Area’s</h3>
<p>About a year ago, <a href="http://haacked.com/archive/2008/11/04/areas-in-aspnetmvc.aspx">Phil Haacked showed a concept called area’s</a> to partition an ASP.NET MVC application. After that, <a href="http://blog.codeville.net/2008/11/05/app-areas-in-aspnet-mvc-take-2/">Steve Sanderson came up with an improved version</a> of the concept.</p>
<p>Although designed to partition an MVC application, area’s are also useful when we want to isolate our MVC application from our existing WebForms app. <a href="http://blog.codeville.net/2008/11/05/app-areas-in-aspnet-mvc-take-2/" target="_blank">The solution from Steve Sanderson</a> almost completely fits our needs, follow the link for more technical details. The only thing I removed was the usage of an Areas subfolder in the project where all the individual MVC sub-applications. Simply didn’t need the extra subfolder and url of the MVC app is closer to the physical structure.</p>
<p>So, I implemented area’s with a specific AreaViewEngine that can lookup views based on the area name and added the extension to the RouteCollection class to add area information when mapping routes. This is how Global.asax.cs looks:</p>
<div id="codeSnippetWrapper" style="border-right: silver 1px solid; padding-right: 4px; border-top: silver 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: silver 1px solid; width: 97.5%; cursor: text; direction: ltr; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: silver 1px solid; font-family: &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4; text-align: left">
<div id="codeSnippet" style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none">
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span style="color: #0000ff">protected</span> <span style="color: #0000ff">void</span> Application_Start(<span style="color: #0000ff">object</span> sender, EventArgs e)</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none">{</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none">    ViewEngines.Engines.Clear();</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none">    ViewEngines.Engines.Add(<span style="color: #0000ff">new</span> AreaViewEngine());</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none">&#160;</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none">    <span style="color: #008000">// Routes</span></pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none">    RegisterRoutes(RouteTable.Routes);</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none">}</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none">&#160;</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">void</span> RegisterRoutes(RouteCollection routes)</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none">{</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none">    routes.IgnoreRoute(<span style="color: #006080">&quot;{resource}.axd/{*pathInfo}&quot;</span>);</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none">    routes.IgnoreRoute(<span style="color: #006080">&quot;{*favicon}&quot;</span>, <span style="color: #0000ff">new</span> { favicon = <span style="color: #006080">@&quot;(.*/)?favicon.ico(/.*)?&quot;</span> });</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none">&#160;</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none">    routes.CreateArea(<span style="color: #006080">&quot;mymvcapp&quot;</span>, <span style="color: #006080">&quot;WebFormsMVCDemo.MyMvcApp.Controllers&quot;</span>,</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none">        routes.MapRoute(<span style="color: #006080">&quot;mymvcapp-defaultroute&quot;</span>, <span style="color: #006080">&quot;mymvcapp/{controller}/{action}/{id}&quot;</span>, <span style="color: #0000ff">new</span> { action = <span style="color: #006080">&quot;Index&quot;</span>, controller = <span style="color: #006080">&quot;Home&quot;</span>, id = <span style="color: #006080">&quot;&quot;</span> })</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none">    );</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none">}</pre>
<p><!--CRLF--></div>
</div>
<p>With the ViewEngine and routes in place, we’re able to run the MVC app from the url /mymvcapp. To make sure the WebForms url’s still work, we just have to add some ignore statements in Global.asax.cs (in our case, exclude .aspx and .ashx from routing):</p>
<div id="codeSnippetWrapper" style="border-right: silver 1px solid; padding-right: 4px; border-top: silver 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: silver 1px solid; width: 97.5%; cursor: text; direction: ltr; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: silver 1px solid; font-family: &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4; text-align: left">
<div id="codeSnippet" style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none">
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">void</span> RegisterRoutes(RouteCollection routes)</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none">{</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none">    routes.IgnoreRoute(<span style="color: #006080">&quot;{resource}.axd/{*pathInfo}&quot;</span>);</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none">    routes.IgnoreRoute(<span style="color: #006080">&quot;{*allaspx}&quot;</span>, <span style="color: #0000ff">new</span> { allaspx = <span style="color: #006080">@&quot;.*\.aspx(/.*)?&quot;</span> });</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none">    routes.IgnoreRoute(<span style="color: #006080">&quot;{*allashx}&quot;</span>, <span style="color: #0000ff">new</span> { allashx = <span style="color: #006080">@&quot;.*\.ashx(/.*)?&quot;</span> });</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none">    routes.IgnoreRoute(<span style="color: #006080">&quot;{*favicon}&quot;</span>, <span style="color: #0000ff">new</span> { favicon = <span style="color: #006080">@&quot;(.*/)?favicon.ico(/.*)?&quot;</span> });</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none">&#160;</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none">    routes.CreateArea(<span style="color: #006080">&quot;mymvcapp&quot;</span>, <span style="color: #006080">&quot;WebFormsMVCDemo.MyMvcApp.Controllers&quot;</span>,</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none">        routes.MapRoute(<span style="color: #006080">&quot;mymvcapp-defaultroute&quot;</span>, <span style="color: #006080">&quot;mymvcapp/{controller}/{action}/{id}&quot;</span>, <span style="color: #0000ff">new</span> { action = <span style="color: #006080">&quot;Index&quot;</span>, controller = <span style="color: #006080">&quot;Home&quot;</span>, id = <span style="color: #006080">&quot;&quot;</span> })</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none">    );</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none">}</pre>
<p><!--CRLF--></div>
</div>
<p>One caveat: when performing the request for /mymvcapp without controller name (and action), the Default.aspx that comes with the MVC projects was loaded, but area’s seem so cause a problem with the default one. Instead of rewriting the url from ‘default.aspx’ to ‘/’, I had to rewrite to url to ‘Home/Index’:</p>
<div id="codeSnippetWrapper" style="border-right: silver 1px solid; padding-right: 4px; border-top: silver 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: silver 1px solid; width: 97.5%; cursor: text; direction: ltr; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: silver 1px solid; font-family: &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4; text-align: left">
<div id="codeSnippet" style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none">
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span style="color: #0000ff">public</span> <span style="color: #0000ff">partial</span> <span style="color: #0000ff">class</span> _Default : Page</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none">{</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none">    <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> Page_Load(<span style="color: #0000ff">object</span> sender, System.EventArgs e)</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none">    {</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none">        <span style="color: #0000ff">string</span> pathToRewriteTo = Request.Path.ToLowerInvariant().Replace(<span style="color: #006080">&quot;default.aspx&quot;</span>, <span style="color: #006080">&quot;Home/Index&quot;</span>);</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none">        HttpContext.Current.RewritePath(pathToRewriteTo, <span style="color: #0000ff">false</span>);</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none">        IHttpHandler httpHandler = <span style="color: #0000ff">new</span> MvcHttpHandler();</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none">        httpHandler.ProcessRequest(HttpContext.Current);</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none">    }</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none">}</pre>
<p><!--CRLF--></div>
</div>
<p>I’m under the impression that I’m missing something very simple, but couldn’t get my fingers behind it, so if you know it, please comment.</p>
<p>&#160;</p>
<p>That’s it. I created a sample project with both WebForms and an MVC app in a subfolder. <a href="http://blogs.taiga.nl/martijn/wp-content/uploads/WebFormsMVCDemo.zip" target="_blank">You can download it here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.taiga.nl/martijn/2009/06/03/aspnet-webforms-and-mvc-together-in-one-project/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

