<?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/"
	
	xmlns:georss="http://www.georss.org/georss"
	xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
	>

<channel>
	<title>ASP.NET &#8211; WiredPrairie</title>
	<atom:link href="blog/archives/tag/asp-net/feed" rel="self" type="application/rss+xml" />
	<link>/blog</link>
	<description>Yet another tech blog.</description>
	<lastBuildDate>Sat, 02 Mar 2013 16:50:53 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.0</generator>
<site xmlns="com-wordpress:feed-additions:1">193486638</site>	<item>
		<title>Windows 8 IIS Express with Windows Authentication Prompts for Credentials</title>
		<link>/blog/index.php/archives/1850</link>
					<comments>/blog/index.php/archives/1850#comments</comments>
		
		<dc:creator><![CDATA[Aaron]]></dc:creator>
		<pubDate>Sat, 02 Mar 2013 16:50:52 +0000</pubDate>
				<category><![CDATA[General]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[Windows 8]]></category>
		<guid isPermaLink="false">/blog/?p=1850</guid>

					<description><![CDATA[If you’re seeing a credentials prompt every time you launch a local IIS or IIS Express web application that requires Windows Authentication, you’ll likely grow as tired of typing in your password as I was. To add to the annoyance, the Remember my credentials checkbox doesn’t work (nothing is saved). The setup: Windows 8 Visual [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>If you’re seeing a credentials prompt every time you launch a local IIS or IIS Express web application that requires Windows Authentication, you’ll likely grow as tired of typing in your password as I was. To add to the annoyance, the <strong>Remember my credentials</strong> checkbox doesn’t work (nothing is saved).</p>
<p><a href="blog/wpcontent/uploads/2013/03/image.png"><img loading="lazy" title="image" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; float: none; padding-top: 0px; padding-left: 0px; margin: 0px auto; border-left: 0px; display: block; padding-right: 0px" border="0" alt="image" src="blog/wpcontent/uploads/2013/03/image_thumb.png" width="443" height="351" /></a></p>
<p>The setup:</p>
<ul>
<li>Windows 8</li>
<li>Visual Studio 2012, .NET 4.5, </li>
<li>ASP.NET MVC web application</li>
<li>Non domain-joined computer (it’s on my home network)</li>
<li>Using a Microsoft account (FKA Live ID) as the local account</li>
<li>Using IIS Express/IIS</li>
<li>Windows Authentication <strong>Enabled</strong></li>
<li>Anonymous Logon <strong>Disabled</strong></li>
</ul>
<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">system.webServer</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">security</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">authentication</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">windowsAuthentication</span> <span class="attr">enabled</span><span class="kwrd">=&quot;true&quot;</span> <span class="kwrd">/&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">anonymousAuthentication</span> <span class="attr">enabled</span><span class="kwrd">=&quot;false&quot;</span> <span class="kwrd">/&gt;</span>
        <span class="kwrd">&lt;/</span><span class="html">authentication</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;/</span><span class="html">security</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">system.webServer</span><span class="kwrd">&gt;</span></pre>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>While there are a few proposed solutions, this is the only one that worked for me so far.</p>
<ol>
<li>Start Internet Explorer</li>
<li>Click the settings Menu</li>
<li>Select <strong>Internet options</strong></li>
<li>Click the <strong>Security </strong>tab</li>
<li>Select <strong>Local intranet</strong></li>
<li>Click <strong>Sites</strong></li>
<li>Click <strong>Advanced</strong></li>
<li>Add <a href="http://localhost/">http://localhost/</a> to the Local intranet zone</li>
<li>Close.</li>
<li>Verify it’s now working.</li>
</ol>
<p><a href="blog/wpcontent/uploads/2013/03/image1.png"><img loading="lazy" title="image" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; float: none; padding-top: 0px; padding-left: 0px; margin: 0px auto; border-left: 0px; display: block; padding-right: 0px" border="0" alt="image" src="blog/wpcontent/uploads/2013/03/image_thumb1.png" width="256" height="290" /></a></p>
<p><a href="blog/wpcontent/uploads/2013/03/image2.png"><img loading="lazy" title="image" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; float: none; padding-top: 0px; padding-left: 0px; margin: 0px auto; border-left: 0px; display: block; padding-right: 0px" border="0" alt="image" src="blog/wpcontent/uploads/2013/03/image_thumb2.png" width="425" height="544" /></a></p>
<p><a href="blog/wpcontent/uploads/2013/03/image3.png"><img loading="lazy" title="image" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; float: none; padding-top: 0px; padding-left: 0px; margin: 0px auto; border-left: 0px; display: block; padding-right: 0px" border="0" alt="image" src="blog/wpcontent/uploads/2013/03/image_thumb3.png" width="416" height="236" /></a></p>
<p><a href="blog/wpcontent/uploads/2013/03/image4.png"><img loading="lazy" title="image" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; float: none; padding-top: 0px; padding-left: 0px; margin: 0px auto; border-left: 0px; display: block; padding-right: 0px" border="0" alt="image" src="blog/wpcontent/uploads/2013/03/image_thumb4.png" width="396" height="351" /></a></p>
<p><a href="blog/wpcontent/uploads/2013/03/image5.png"><img loading="lazy" title="image" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; float: none; padding-top: 0px; padding-left: 0px; margin: 0px auto; border-left: 0px; display: block; padding-right: 0px" border="0" alt="image" src="blog/wpcontent/uploads/2013/03/image_thumb5.png" width="396" height="351" /></a></p>
<p>Done.</p>
<p>Alternatives welcomed. :)</p>
]]></content:encoded>
					
					<wfw:commentRss>/blog/index.php/archives/1850/feed</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1850</post-id>	</item>
		<item>
		<title>Knockout binding for JavaScript route fixup</title>
		<link>/blog/index.php/archives/1820</link>
					<comments>/blog/index.php/archives/1820#comments</comments>
		
		<dc:creator><![CDATA[Aaron]]></dc:creator>
		<pubDate>Sat, 26 Jan 2013 02:48:30 +0000</pubDate>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Knockout]]></category>
		<category><![CDATA[MVC]]></category>
		<guid isPermaLink="false">/blog/?p=1820</guid>

					<description><![CDATA[Part one. After the first round, I felt compelled to KnockOut the code a bit more. I’d mentioned I wasn’t pleased with the code exactly. It needed some refactoring. So, I’ve created a new Knockout binding handler. This binding handler replaces&#160; named parameters with a model’s properties in a path. For example, given this object: [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a href="blog/archives/1800">Part one.</a></p>
<p>After the first round, I felt compelled to KnockOut the code a bit more. I’d mentioned I wasn’t pleased with the code exactly. It needed some refactoring.</p>
<p>So, I’ve created a new Knockout binding handler. This binding handler replaces&#160; named parameters with a model’s properties in a path. </p>
<p>For example, given this object:</p>
<table cellspacing="0" cellpadding="2" width="400" border="1">
<tbody>
<tr>
<td valign="top" width="200"><strong>Property Name</strong></td>
<td valign="top" width="200"><strong>Value</strong></td>
</tr>
<tr>
<td valign="top" width="200">id</td>
<td valign="top" width="200">A123</td>
</tr>
<tr>
<td valign="top" width="200">first_name</td>
<td valign="top" width="200">Aaron</td>
</tr>
<tr>
<td valign="top" width="200">state</td>
<td valign="top" width="200">WI</td>
</tr>
</tbody>
</table>
<p>The following paths would be converted thusly:</p>
<table cellspacing="0" cellpadding="2" width="400" border="1">
<tbody>
<tr>
<td valign="top" width="200"><strong>Original</strong></td>
<td valign="top" width="200"><strong>Replaced</strong></td>
</tr>
<tr>
<td valign="top" width="200">/person/{id}</td>
<td valign="top" width="200">/person/A123</td>
</tr>
<tr>
<td valign="top" width="200">/person/{state}/{id}</td>
<td valign="top" width="200">/person/WI/A123</td>
</tr>
</tbody>
</table>
<p>You get the idea. Here’s the JavaScript code:</p>
<pre class="csharpcode">ko.bindingHandlers[<span class="str">'route'</span>] = {
    <span class="rem">// Examples: </span>
    <span class="rem">//      &lt;a data-bind=&quot;route: {model: $data, url: 'person_details', attr: 'href' }&quot; &gt;</span>
    <span class="rem">// or, you can shortcut the syntax to default to the currently bound object and just pass </span>
    <span class="rem">// the url or the route name as a string directly</span>
    <span class="rem">//      &lt;a data-bind=&quot;route: 'person_details' }&quot; &gt;</span>
    update: <span class="kwrd">function</span> (element, valueAccessor, allBindingsAccessor, $data) {
        <span class="kwrd">var</span> valueUnwrapped = ko.utils.unwrapObservable(valueAccessor());
        <span class="kwrd">var</span> options = ko.bindingHandlers.route.options || {};

        <span class="rem">// look for the model property </span>
        <span class="kwrd">var</span> model = ko.utils.unwrapObservable(valueUnwrapped[<span class="str">'model'</span>]);
        <span class="kwrd">if</span> (<span class="kwrd">typeof</span> model !== <span class="str">'object'</span>) {

            model = ko.utils.unwrapObservable($data);
            <span class="kwrd">if</span> (<span class="kwrd">typeof</span> model === <span class="str">'undefined'</span> || model === <span class="kwrd">null</span>) {
                <span class="kwrd">throw</span> <span class="kwrd">new</span> Error(<span class="str">'set route model to object (or nothing bound?)'</span>);
            }
        }

        <span class="rem">// look for the url property first</span>
        <span class="kwrd">var</span> url = ko.utils.unwrapObservable(valueUnwrapped[<span class="str">'url'</span>]);
        <span class="rem">// validate we've got something as a url (might be a name, might be a full url)        </span>
        <span class="kwrd">if</span> (<span class="kwrd">typeof</span> url !== <span class="str">'string'</span> || url == <span class="str">&quot;&quot;</span>) {
            url = valueUnwrapped;
            <span class="kwrd">if</span> (<span class="kwrd">typeof</span> url !== <span class="str">'string'</span> || url == <span class="str">&quot;&quot;</span>) {
                <span class="kwrd">throw</span> <span class="kwrd">new</span> Error(<span class="str">&quot;set route url property to route name or url directly&quot;</span>);
            }
        }

        <span class="rem">// is it on the keyed collection?</span>
        <span class="kwrd">var</span> map = options.map;
        <span class="kwrd">if</span> (<span class="kwrd">typeof</span> map !== <span class="str">'undefined'</span> &amp;&amp; map !== <span class="kwrd">null</span>) {
            <span class="kwrd">if</span> (map.hasOwnProperty(url)) {
                url = map[url];
            }
        }
        <span class="rem">// check for a routing function as well</span>
        <span class="kwrd">var</span> fn = options.routeNameToUrl;
        <span class="kwrd">if</span> (<span class="kwrd">typeof</span> fn === <span class="str">'function'</span>) { url = fn.call(<span class="kwrd">null</span>, url); }
        <span class="rem">// did we get something meaningful?</span>
        <span class="kwrd">if</span> (url !== <span class="kwrd">null</span> &amp;&amp; url !== <span class="str">''</span> &amp;&amp; url.length &gt; 0) {
            url = ko.bindingHandlers.route.buildUrl(url, model);            
        }
        <span class="rem">// the url might need some fixin after a routing, anything goes here (might just be a default)</span>
        fn = options.fixUrl;
        <span class="kwrd">if</span> (<span class="kwrd">typeof</span> fn === <span class="str">'function'</span>) { url = fn.call(<span class="kwrd">null</span>, url); }
        element.setAttribute(ko.utils.unwrapObservable(valueUnwrapped[<span class="str">'attr'</span>]) || <span class="str">'href'</span>, url);
    },    

    <span class="rem">// given a model, this function replaces named parameters in a simple string </span>
    <span class="rem">// with values from the model</span>
    <span class="rem">//     /path/to/some/{id}/{category}</span>
    <span class="rem">// with object { 'id' : 'abc', 'category' : 'cars' }</span>
    <span class="rem">// becomes</span>
    <span class="rem">//     /path/to/some/abc/cars</span>
    buildUrl : <span class="kwrd">function</span>(url, model) {
        <span class="rem">// unfixed if there's not a thing</span>
        <span class="kwrd">if</span> (<span class="kwrd">typeof</span> model === <span class="str">'undefined'</span> || model === <span class="kwrd">null</span>) { <span class="kwrd">return</span> url; }

        <span class="kwrd">var</span> propValue;
        <span class="kwrd">for</span> (<span class="kwrd">var</span> propName <span class="kwrd">in</span> model) {                
            <span class="kwrd">if</span> (model.hasOwnProperty(propName)) {
                propValue = model[propName];
                <span class="kwrd">if</span> (ko) { propValue = ko.utils.unwrapObservable(propValue); }

                <span class="kwrd">if</span> (<span class="kwrd">typeof</span> propValue === <span class="str">'undefined'</span> || propValue === <span class="kwrd">null</span>) {
                    propValue = <span class="str">&quot;&quot;</span>;
                } <span class="kwrd">else</span> {
                    propValue = propValue.toString();
                }
                url = url.replace(<span class="str">'{'</span> + propName.toLowerCase() + <span class="str">'}'</span>, propValue);
            }
        }
        <span class="kwrd">return</span> url;
    },

    options: {
        <span class="rem">// ** convert a route name to a url through whatever means you'd like</span>
        <span class="rem">// routeNameToUrl : function(routeName) { return url; } </span>

        <span class="rem">// ** anything you want, called after routeNameToUrl, might add a virtual directory</span>
        <span class="rem">// ** for example</span>
        <span class="rem">// fixUrl: function(url) { return url;  }  </span>

        <span class="rem">// ** A map route names to URLs **</span>
        <span class="rem">// all other functions are called if set (to possibly override this)</span>
        <span class="rem">// this is not required if you use one of the other functions</span>
        <span class="rem">// map : { 'a_route_name' : '/path/to/something/{id}/{action}' }        </span>
    }
};</pre>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>In another JavaScript file, I did initialize some of the options:</p>
<pre class="csharpcode">ko.bindingHandlers.route.options.routeNameToUrl = getRoute;
ko.bindingHandlers.route.options.fixUrl = app_url;</pre>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>The <strong>getRoute</strong> function just maps a route name to a path, and the <strong>app_url</strong> prepends the virtual directory to the path as needed.</p>
<p>Here it is in use:</p>
<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">div</span> <span class="attr">data-bind</span><span class="kwrd">=&quot;foreach: data.persons&quot;</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">h3</span> <span class="attr">class</span><span class="kwrd">=&quot;title&quot;</span> <span class="attr">data-bind</span><span class="kwrd">=&quot;text: Title&quot;</span><span class="kwrd">&gt;&lt;/</span><span class="html">h3</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">div</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">a</span> <span class="attr">data-bind</span><span class="kwrd">=&quot;route: { model: $data, url: 'person_details', attr: 'href' } &quot;</span><span class="kwrd">&gt;</span>Details2<span class="kwrd">&lt;/</span><span class="html">a</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">a</span> <span class="attr">data-bind</span><span class="kwrd">=&quot;route: '/data/details/{id}/{title}' &quot;</span><span class="kwrd">&gt;</span>Details<span class="kwrd">&lt;/</span><span class="html">a</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">a</span> <span class="attr">data-bind</span><span class="kwrd">=&quot;route: 'person_details' &quot;</span><span class="kwrd">&gt;</span>Details<span class="kwrd">&lt;/</span><span class="html">a</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;/</span><span class="html">div</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">div&gt;</span></pre>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>You’ll probably like the new way better syntactically at least compared to the <a href="blog/archives/1800">old</a> way. A route binding requires one input when used in it’s most basic form:</p>
<ul>
<li><strong>url = </strong>the URL or route name to use as the template for the replacement. It should contain (or later resolve to) curly-braced enclosed property name keys which will be substituted by values from the model. The value of the property could be either a route name (see options below) or a path.</li>
</ul>
<p>When using just the basic form you can use the shortened syntax:</p>
<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">a</span> <span class="attr">data-bind</span><span class="kwrd">=&quot;route: 'research_details' &quot;</span><span class="kwrd">&gt;</span>Details<span class="kwrd">&lt;/</span><span class="html">a</span><span class="kwrd">&gt;</span></pre>
<p>This handily binds to the current object (via the bindingContext.$data property of the bindingHandler update function call, which is <strong>also </strong>the fourth parameter, which I’ve renamed to $data rather than the typical viewModel). So, you won’t need to necessarily (explicitly) set the model for the binding.</p>
<p>If you need a a bit more control, you can change the syntax and get access to a few other options (including direct access to the model you want to bind to if the current item isn’t directly what you want to use).</p>
<ul>
<li><strong>model</strong> = this is the object that contains the properties and values to be used as replacements within the url </li>
<li><strong>attr </strong>(optional) = the name of the attribute to set the generated url into. Defaults to href if not set.</li>
</ul>
<p>There are a few global options you can control as well:</p>
<ul>
<li><strong>routeNameToUrl </strong>= (function)(routeName) optionally, given a route name, should return the path (or the original value). Here you can do a lookup of routeName to path. </li>
<li><strong>map</strong> = {object} the object properties should be route names and set equal to the path. this optional lookup is performed before the routeNameToUrl function is called. </li>
<li><strong>fixUrl</strong> = (function)(url) do anything here. this is called after the mapping and routeNameToUrl is optionally called. I use this to correct javascript Ajax request paths by appending the application virtual directory</li>
</ul>
<p>(Thanks to <a href="http://www.knockmeout.net/">Ryan</a> for the suggestion to use the $data on the bindingContext, and then again for the nudge to just use the 4th parameter. <img class="wlEmoticon wlEmoticon-smile" style="border-top-style: none; border-left-style: none; border-bottom-style: none; border-right-style: none" alt="Smile" src="blog/wpcontent/uploads/2013/01/wlEmoticon-smile.png" /> )</p>
]]></content:encoded>
					
					<wfw:commentRss>/blog/index.php/archives/1820/feed</wfw:commentRss>
			<slash:comments>5</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1820</post-id>	</item>
		<item>
		<title>Custom RouteHandler in ASP.NET 4.0</title>
		<link>/blog/index.php/archives/921</link>
		
		<dc:creator><![CDATA[Aaron]]></dc:creator>
		<pubDate>Fri, 12 Mar 2010 01:34:00 +0000</pubDate>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<guid isPermaLink="false">/blog/index.php/archives/921</guid>

					<description><![CDATA[It’s great that some of the innovations from ASP.NET MVC 1.0 were moved into the ASP.NET 4.0 platform. One of those was the RouteTable. I hadn’t written a custom RouteHandler before, so I thought I’d do a simple one as a demo for myself (and any others who are interested). This is just an example [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>It’s great that some of the innovations from ASP.NET MVC 1.0 were moved into the ASP.NET 4.0 platform. One of those was the <strong>RouteTable</strong>. I hadn’t written a custom RouteHandler before, so I thought I’d do a simple one as a demo for myself (and any others who are interested).</p>
<p>This is just an example of how to build one – <strong>it’s not secure</strong>. </p>
<pre class="code"><span style="color: blue">using </span>System;
<span style="color: blue">using </span>System.Collections.Generic;
<span style="color: blue">using </span>System.Linq;
<span style="color: blue">using </span>System.Web;
<span style="color: blue">using </span>System.Web.Security;
<span style="color: blue">using </span>System.Web.SessionState;
<span style="color: blue">using </span>System.Web.Routing;
<span style="color: blue">using </span>System.IO;

<span style="color: blue">namespace </span>TestWebApplication1
{
    <span style="color: blue">public class </span><span style="color: #2b91af">Global </span>: System.Web.<span style="color: #2b91af">HttpApplication
    </span>{
        <span style="color: blue">void </span>Application_Start(<span style="color: blue">object </span>sender, <span style="color: #2b91af">EventArgs </span>e)
        {
            <span style="color: #2b91af">RouteTable</span>.Routes.Add(<span style="color: blue">new </span><span style="color: #2b91af">Route</span>(<span style="color: #a31515">&quot;Assets/{locale}/{assetID}&quot;</span>, <span style="color: blue">new </span><span style="color: #2b91af">CustomRouteHandler</span>()));
        }
    }

    <span style="color: blue">public class </span><span style="color: #2b91af">CustomRouteHandler </span>: <span style="color: #2b91af">IRouteHandler
    </span>{
        <span style="color: blue">public </span><span style="color: #2b91af">IHttpHandler </span>GetHttpHandler(<span style="color: #2b91af">RequestContext </span>requestContext)
        {            
            <span style="color: blue">return new </span><span style="color: #2b91af">SimpleFileHttpHandler</span>(requestContext);
        }
    }

    <span style="color: blue">public class </span><span style="color: #2b91af">SimpleFileHttpHandler </span>: <span style="color: #2b91af">IHttpHandler
    </span>{
        <span style="color: blue">private </span><span style="color: #2b91af">RequestContext </span>_requestContext;
        <span style="color: blue">private </span><span style="color: #2b91af">HttpContext </span>_httpContext;

        <span style="color: blue">public </span><span style="color: #2b91af">RequestContext </span>RequestContext { <span style="color: blue">get</span>; <span style="color: blue">private set</span>; }

        <span style="color: blue">public </span>SimpleFileHttpHandler(<span style="color: #2b91af">RequestContext </span>requestContext)
        {
            _requestContext = requestContext;
        }

        <span style="color: blue">public bool </span>IsReusable
        {
            <span style="color: blue">get </span>{ <span style="color: blue">return false</span>; }
        }

        <span style="color: blue">public void </span>ProcessRequest(<span style="color: #2b91af">HttpContext </span>context)
        {
            _httpContext = context;

            <span style="color: blue">string </span>assetID = _requestContext.RouteData.Values[<span style="color: #a31515">&quot;assetID&quot;</span>].ToString();
            <span style="color: blue">string </span>locale = _requestContext.RouteData.Values[<span style="color: #a31515">&quot;locale&quot;</span>].ToString();

            <span style="color: blue">if </span>(<span style="color: blue">string</span>.IsNullOrWhiteSpace(assetID) || <span style="color: blue">string</span>.IsNullOrWhiteSpace(locale)) {
                <span style="color: blue">throw new </span><span style="color: #2b91af">ArgumentException</span>();
            }
            <span style="color: green">// this is not adaquate and definitely not secure as it would allow any file to be selected and downloaded
            // needs to prevent any sort of hack attempts using encoded paths, etc. should just be a relative path within the
            // folder that contains the content and no more. 
            </span><span style="color: blue">string </span>path = _httpContext.Request.MapPath(<span style="color: #a31515">&quot;~/Content/&quot; </span>+ assetID, <span style="color: #a31515">&quot;&quot;</span>, <span style="color: blue">false</span>);
            <span style="color: blue">if </span>(<span style="color: #2b91af">File</span>.Exists(path))
            {               
                <span style="color: green">// hard coded to the image/jpg type (obviously needs to adjust)
                </span>context.Response.AddHeader(<span style="color: #a31515">&quot;Content-Type&quot;</span>, <span style="color: #a31515">&quot;image/jpg&quot;</span>);
                context.Response.AddHeader(<span style="color: #a31515">&quot;Content-Length&quot;</span>, <span style="color: blue">new </span><span style="color: #2b91af">FileInfo</span>(path).Length.ToString());
                context.Response.WriteFile(path);
            }
        }
    }


}</pre>
<p>To use it, I created a folder called Content and copied one of the sample photos included with Windows into the folder, and then modified Default.aspx:</p>
<pre class="code"><span style="background: yellow">&lt;%</span><span style="color: blue">@ </span><span style="color: maroon">Page </span><span style="color: red">Title</span><span style="color: blue">=&quot;Home Page&quot; </span><span style="color: red">Language</span><span style="color: blue">=&quot;C#&quot; </span><span style="color: red">MasterPageFile</span><span style="color: blue">=&quot;~/Site.master&quot; </span><span style="color: red">AutoEventWireup</span><span style="color: blue">=&quot;true&quot;
    </span><span style="color: red">CodeBehind</span><span style="color: blue">=&quot;Default.aspx.cs&quot; </span><span style="color: red">Inherits</span><span style="color: blue">=&quot;TestWebApplication1._Default&quot; </span><span style="background: yellow">%&gt;

</span><span style="color: blue">&lt;</span><span style="color: maroon">asp</span><span style="color: blue">:</span><span style="color: maroon">Content </span><span style="color: red">ID</span><span style="color: blue">=&quot;HeaderContent&quot; </span><span style="color: red">runat</span><span style="color: blue">=&quot;server&quot; </span><span style="color: red">ContentPlaceHolderID</span><span style="color: blue">=&quot;HeadContent&quot;&gt;
&lt;/</span><span style="color: maroon">asp</span><span style="color: blue">:</span><span style="color: maroon">Content</span><span style="color: blue">&gt;
&lt;</span><span style="color: maroon">asp</span><span style="color: blue">:</span><span style="color: maroon">Content </span><span style="color: red">ID</span><span style="color: blue">=&quot;BodyContent&quot; </span><span style="color: red">runat</span><span style="color: blue">=&quot;server&quot; </span><span style="color: red">ContentPlaceHolderID</span><span style="color: blue">=&quot;MainContent&quot;&gt;
    &lt;</span><span style="color: maroon">h2</span><span style="color: blue">&gt;
        </span>Welcome to the Route Table Demonstrator
    <span style="color: blue">&lt;/</span><span style="color: maroon">h2</span><span style="color: blue">&gt;
    &lt;</span><span style="color: maroon">h3</span><span style="color: blue">&gt;</span>This one should work as it's using the not-so-magical route table and a custom iroutehandler.<span style="color: blue">&lt;/</span><span style="color: maroon">h3</span><span style="color: blue">&gt;
    &lt;</span><span style="color: maroon">p</span><span style="color: blue">&gt;
        </span><span style="color: red">&amp;lt;</span>img src=<span style="color: red">&amp;quot;</span>/Assets/en-us/Penguins.jpg<span style="color: red">&amp;quot; </span>width=<span style="color: red">&amp;quot;</span>320<span style="color: red">&amp;quot; </span>height=<span style="color: red">&amp;quot;</span>200<span style="color: red">&amp;quot; </span>/<span style="color: red">&amp;gt;
    </span><span style="color: blue">&lt;/</span><span style="color: maroon">p</span><span style="color: blue">&gt;
    &lt;</span><span style="color: maroon">p</span><span style="color: blue">&gt;
        &lt;</span><span style="color: maroon">img </span><span style="color: red">src</span><span style="color: blue">=&quot;/Assets/en-us/Penguins.jpg&quot; </span><span style="color: red">width</span><span style="color: blue">=&quot;320&quot; </span><span style="color: red">height</span><span style="color: blue">=&quot;200&quot; /&gt;
    &lt;/</span><span style="color: maroon">p</span><span style="color: blue">&gt;
    &lt;</span><span style="color: maroon">h3</span><span style="color: blue">&gt;</span>THis one shouldn't work due to security in web.config for the folder<span style="color: blue">&lt;/</span><span style="color: maroon">h3</span><span style="color: blue">&gt;
    &lt;</span><span style="color: maroon">p</span><span style="color: blue">&gt;</span><span style="color: red">&amp;lt;</span>img src=<span style="color: red">&amp;quot;</span>/Content/Penguins.jpg<span style="color: red">&amp;quot; </span>/<span style="color: red">&amp;gt;</span><span style="color: blue">&lt;/</span><span style="color: maroon">p</span><span style="color: blue">&gt;
    &lt;</span><span style="color: maroon">p</span><span style="color: blue">&gt;
        &lt;</span><span style="color: maroon">img </span><span style="color: red">src</span><span style="color: blue">=&quot;/Content/Penguins.jpg&quot; /&gt;
    &lt;/</span><span style="color: maroon">p</span><span style="color: blue">&gt;    
&lt;/</span><span style="color: maroon">asp</span><span style="color: blue">:</span><span style="color: maroon">Content</span><span style="color: blue">&gt;

</span></pre>
<p><a href="http://11011.net/software/vspaste"></a>In the Content Folder, I added a web.config file to prevent direct access to the content within the folder:</p>
<pre class="code"><span style="color: blue">&lt;?</span><span style="color: #a31515">xml </span><span style="color: red">version</span><span style="color: blue">=</span>&quot;<span style="color: blue">1.0</span>&quot;<span style="color: blue">?&gt;
&lt;</span><span style="color: #a31515">configuration</span><span style="color: blue">&gt;

  &lt;</span><span style="color: #a31515">system.web</span><span style="color: blue">&gt;
    &lt;</span><span style="color: #a31515">authorization</span><span style="color: blue">&gt;
      &lt;</span><span style="color: #a31515">deny </span><span style="color: red">users</span><span style="color: blue">=</span>&quot;<span style="color: blue">*</span>&quot;<span style="color: blue">/&gt;
    &lt;/</span><span style="color: #a31515">authorization</span><span style="color: blue">&gt;
 
  &lt;/</span><span style="color: #a31515">system.web</span><span style="color: blue">&gt;

  &lt;</span><span style="color: #a31515">system.webServer</span><span style="color: blue">&gt;
     &lt;</span><span style="color: #a31515">modules </span><span style="color: red">runAllManagedModulesForAllRequests</span><span style="color: blue">=</span>&quot;<span style="color: blue">true</span>&quot;<span style="color: blue">/&gt;
  &lt;/</span><span style="color: #a31515">system.webServer</span><span style="color: blue">&gt;
&lt;/</span><span style="color: #a31515">configuration</span><span style="color: blue">&gt;

</span></pre>
<p>This should work without modification on IIS7+ and Visual Studio 2010.</p>
<p><img loading="lazy" style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="blog/wpcontent/uploads/2010/03/image3.png" width="400" height="291" /></p>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">921</post-id>	</item>
		<item>
		<title>Disabling automatic Sys.UI.Control attachment</title>
		<link>/blog/index.php/archives/890</link>
		
		<dc:creator><![CDATA[Aaron]]></dc:creator>
		<pubDate>Sun, 17 Jan 2010 18:26:54 +0000</pubDate>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<guid isPermaLink="false">/blog/index.php/archives/890</guid>

					<description><![CDATA[If you’re using the Microsoft Ajax Library (learn), you may not always want to start the automatic “attach” process that takes place when the page loads. It’s easy to disable, but not yet documented any place I could find easily. &#60;script src=&#34;Scripts/MicrosoftAjax/Start.debug.js&#34; type=&#34;text/javascript&#34;&#62;&#60;/script&#62; &#60;script type=&#34;text/javascript&#34;&#62; var ajaxPath = &#34;&#34;; Sys.activateDom = false; All you must [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>If you’re using the Microsoft Ajax Library (<a href="http://www.asp.net/ajaxlibrary/learn.ashx" target="_blank">learn</a>), you may not always want to start the automatic “attach” process that takes place when the page loads. It’s easy to disable, but not yet documented any place I could find easily.</p>
<pre class="code"><span style="color: blue">&lt;</span><span style="color: #a31515">script </span><span style="color: red">src</span><span style="color: blue">=&quot;Scripts/MicrosoftAjax/Start.debug.js&quot; </span><span style="color: red">type</span><span style="color: blue">=&quot;text/javascript&quot;&gt;&lt;/</span><span style="color: #a31515">script</span><span style="color: blue">&gt;
&lt;</span><span style="color: #a31515">script </span><span style="color: red">type</span><span style="color: blue">=&quot;text/javascript&quot;&gt;

    var </span>ajaxPath = <span style="color: #a31515">&quot;&quot;</span>;

    Sys.activateDom = <span style="color: blue">false</span>;</pre>
<p>All you must do is set <strong>Sys.activateDom</strong> to <strong>false</strong> as shown above (make sure this is set <strong>after</strong> the new Start.js JavaScript file loads, otherwise your code will crash when you try to set the Sys object before it has been properly constructed). </p>
<p>Then, to begin the attach process, just call <strong>Sys.activateElements</strong>:</p>
<pre class="code">Sys.activateElements(document.documentElement);</pre>
<p>In the code line above, though I’ve specified that I want the entire HTML document activated, you could provide any element you want as a starting point (for example to optimize the use of the library and prevent unnecessary DOM searching for example).</p>
<p>I’m adding the delay in some JavaScript code because I wanted to set up a few variables in advance of the attach occurring. I tend to write my JavaScript code in an object oriented fashion these days (using the prototype pattern), including code that is interacting with the DOM. In this case, I’ll create a class that represents the logic of the page rather than following the typical purely functional model that is done on many JavaScript pages. But, when using the “<strong>eval</strong>” syntax of the Microsoft Ajax library “{{ code }}”, occasionally, I’ll need to delay the <strong>eval</strong> or the page will crash. </p>
<p>From my recent post on making a simple <a href="blog/archives/885" target="_blank">command extension to the Microsoft Ajax library</a>, I wanted to make that more object oriented by referring to an instance of my class, rather than pointing directly to a function:</p>
<pre class="code"><span style="color: blue">&lt;</span><span style="color: #a31515">body sys</span><span style="color: blue">:</span><span style="color: red">attach</span><span style="color: blue">=&quot;wpc&quot; 
    </span><span style="color: #a31515">wpc</span><span style="color: blue">:</span><span style="color: red">onbubbleevent</span><span style="color: blue">=&quot;{{$view.onCommand}}&quot;  
    </span><span style="color: #a31515">xmlns</span><span style="color: blue">:</span><span style="color: red">sys</span><span style="color: blue">=&quot;javascript:Sys&quot; </span><span style="color: #a31515">xmlns</span><span style="color: blue">:</span><span style="color: red">wpc</span><span style="color: blue">=&quot;javascript:WiredPrairie.Commanding&quot;&gt;
</span></pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p><strong>$view </strong>represents the instance of my page’s behavior. However, if the attach were to occur too early, this variable is not yet set. I’m using the slick <a href="http://www.asp.net/ajaxlibrary/HOW%20TO%20Load%20a%20Custom%20Script%20with%20Dependencies.ashx">script loading functionality</a> of the ajax library, specifying the various JavaScript libraries and their dependencies, including my page’s behavior. It’s not until that JavaScript code is loaded that the code can create an instance – and that could be AFTER the page has already done the attach logic. The attach happens before <strong>Sys.onReady</strong> for example. (Sys.<strong>onDomReady</strong> happens before <strong>onReady</strong>, but not all JavaScript files may have been downloaded).</p>
<pre class="code">Sys.onReady(<span style="color: blue">function</span>() {
    $view = <span style="color: blue">new </span>WiredPrairie.MainView();
    
    Sys.activateElements(document.documentElement);</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>When using the <strong>sys:attach</strong> attribute, note that the attach and instantiation process happens <strong>before</strong> any code you’ve specified in <strong>onReady</strong> is executed (Microsoft currently uses the same method for determining when everything is ready by adding a function call to <strong>onReady</strong> – but their call is first in the queue). </p>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">890</post-id>	</item>
	</channel>
</rss>
