<?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#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Notion Studio</title>
	<atom:link href="http://notionstudio.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://notionstudio.wordpress.com</link>
	<description>Just another WordPress.com site</description>
	<lastBuildDate>Sun, 06 Mar 2011 02:14:39 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='notionstudio.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Notion Studio</title>
		<link>http://notionstudio.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://notionstudio.wordpress.com/osd.xml" title="Notion Studio" />
	<atom:link rel='hub' href='http://notionstudio.wordpress.com/?pushpress=hub'/>
		<item>
		<title>nopCommerce SuperAdmin and Access Control</title>
		<link>http://notionstudio.wordpress.com/2011/03/06/nopcommerce-superadmin-and-access-control/</link>
		<comments>http://notionstudio.wordpress.com/2011/03/06/nopcommerce-superadmin-and-access-control/#comments</comments>
		<pubDate>Sun, 06 Mar 2011 01:58:52 +0000</pubDate>
		<dc:creator>Slayter</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">https://notionstudio.wordpress.com/?p=195</guid>
		<description><![CDATA[The nopCommerce access control is fantastic and it achieves its purpose fully. If for example, me as the ultimate administrator doesn’t want the Staff users to see my PalPal configuration settings, I can simply disable the access from the list and they will get an access denied message when they try that link. However, there [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=notionstudio.wordpress.com&amp;blog=14839848&amp;post=195&amp;subd=notionstudio&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The nopCommerce access control is fantastic and it achieves its purpose fully. If for example, me as the ultimate administrator doesn’t want the Staff users to see my PalPal configuration settings, I can simply disable the access from the list and they will get an access denied message when they try that link. However, there are cases where us as a consultant / developer we want to refrain the users (owner or staff) from seeing some of the available features for various reasons – maybe you didn’t sell that to them, maybe that’s not applicable to their business (the simpler the application the better). It could be sometimes confusing being a business owner but got denied access to part of your website. In addition, in order to handle such “exceptions” you need good documentations and overtime it just increases your maintenance costs. Hence I am adding a <strong>SuperAdmin</strong> property to the <strong>Customer</strong> class and also a custom configuration setting in web.config to achieve the hiding of some features. The reason for adding this into the web.config is to help ourselves remember what we’ve done in the future. </p>
<p>First in <strong>~/Libraries/Nop.BusinessLogic/Customer/Customer.cs</strong> I am adding a public property called <strong>IsSuperAdmin</strong>. </p>
<pre class="code"><span style="color:gray;">/// &lt;summary&gt;
/// </span><span style="color:green;">Gets a boolean indicating if this custom is a Super Admin (CustomerRoleId == 1)
</span><span style="color:gray;">/// &lt;/summary&gt;
</span><span style="color:blue;">public bool </span>IsSuperAdmin
{
<span style="color:blue;">    get
    </span>{
        <span style="color:blue;">if </span>(<span style="color:blue;">this</span>.CustomerRoles.SingleOrDefault(t =&gt; t.CustomerRoleId == 1) != <span style="color:blue;">null</span>)
        {
            <span style="color:blue;">return true</span>;
        }
        <span style="color:blue;">else
        </span>{
            <span style="color:blue;">return false</span>;
        }
    }
}</pre>
<p>It’s defining the CustomerRold with ID = 1 as the “Super Admin” role, which means that you will need to make sure in the database that the one with ID = 1 is indeed the customer role you want to have the ultimate access. Ideally there should be a column in the Customer table for this flag, but I think this is the easiest way without modifying the data structure. </p>
<p>Next I will add a new section to NopConfig in web.config, which I am calling <strong>AdminSettings</strong> (Of course you could name it as whatever makes most sense to you).</p>
<pre class="code"><span style="color:blue;">&lt;</span><span style="color:#a31515;">NopConfig</span><span style="color:blue;">&gt;
    …</span><span style="color:blue;">            &lt;</span><span style="color:#a31515;">AdminSettings</span><span style="color:blue;">&gt;        </span><span style="color:blue;">&lt;</span><span style="color:#a31515;">AdminSetting </span><span style="color:red;">key</span><span style="color:blue;">=</span>&quot;<span style="color:blue;">CategorySEOTabVisibility</span>&quot; <span style="color:red;">value</span><span style="color:blue;">=</span>&quot;<span style="color:blue;">false</span>&quot; <span style="color:blue;">/&gt;</span><span style="color:blue;">    &lt;/</span><span style="color:#a31515;">AdminSettings</span><span style="color:blue;">&gt;</span><span style="color:blue;">&lt;/</span><span style="color:#a31515;">NopConfig</span><span style="color:blue;">&gt;
</span></pre>
<p>The <strong>NopConfig</strong> class handles the custom config section <span style="color:blue;">&lt;</span><span style="color:#a31515;">NopConfig</span><span style="color:blue;">&gt; </span> in web.config. So I am adding a property called <strong>AdminSettings</strong> in <strong>~/Libraries/BusinessLogic/Configuration/NopConfig.cs</strong> to store this new <span style="color:blue;">&lt;/</span><span style="color:#a31515;">AdminSettings</span><span style="color:blue;">&gt;</span> config section. </p>
<pre class="code"><span style="color:blue;">private static </span><span style="color:#2b91af;">Dictionary</span>&lt;<span style="color:blue;">string</span>, <span style="color:blue;">string</span>&gt; _adminSettings = <span style="color:blue;">null</span>;
<span style="color:blue;">public static </span><span style="color:#2b91af;">Dictionary</span>&lt;<span style="color:blue;">string</span>, <span style="color:blue;">string</span>&gt; AdminSettings
{
    <span style="color:blue;">get </span>{ <span style="color:blue;">return </span>_adminSettings; }
}</pre>
<p>The ideal place to initialize this property is in the <strong>Create</strong> method. If you follow the code path, you can see that these config settings are initialized in global.asax. </p>
<pre class="code"><span style="color:blue;">public object </span>Create(<span style="color:blue;">object </span>parent, <span style="color:blue;">object </span>configContext, <span style="color:#2b91af;">XmlNode </span>section){
<span style="color:green;">    // Other code
    </span><span style="color:#2b91af;">XmlNode </span>adminSettingNodes = section.SelectSingleNode(<span style="color:#a31515;">&quot;AdminSettings&quot;</span>);
    <span style="color:blue;">if </span>(adminSettingNodes != <span style="color:blue;">null</span>)
    {
        _adminSettings = <span style="color:blue;">new </span><span style="color:#2b91af;">Dictionary</span>&lt;<span style="color:blue;">string</span>, <span style="color:blue;">string</span>&gt;();
        <span style="color:blue;">foreach </span>(<span style="color:#2b91af;">XmlNode </span>pdNode <span style="color:blue;">in </span>adminSettingNodes.ChildNodes)
        {
            <span style="color:blue;">if </span>(<span style="color:blue;">string</span>.Compare(pdNode.Name.Trim(), <span style="color:#a31515;">&quot;adminsetting&quot;</span>, <span style="color:blue;">true</span>) == 0)
            {
                _adminSettings.Add((<span style="color:blue;">string</span>)pdNode.Attributes[<span style="color:#a31515;">&quot;key&quot;</span>].Value, (<span style="color:blue;">string</span>)pdNode.Attributes[<span style="color:#a31515;">&quot;value&quot;</span>].Value);
            }
        }
    }
    <span style="color:blue;">return null</span>;
}</pre>
<p>&#160;</p>
<p>With all of these in place, we can start to hide out some of the components in the admin pages. For example, if we wish to hide the SEO tab in the category editing page. We will use the following line in <strong>Page_Load</strong> of the <strong>CategoryDetailsControl</strong> class (~/Administration/Modules/CategoryDetails.ascx.cs)</p>
<pre class="code">pnlCategorySEO.Enabled = pnlCategorySEO.Visible = ((!<span style="color:#2b91af;">NopConfig</span>.AdminSettings.ContainsKey(<span style="color:#a31515;">&quot;CategorySEOTabVisibility&quot;</span>)) || <span style="color:#2b91af;">Boolean</span>.Parse(<span style="color:#2b91af;">NopConfig</span>.AdminSettings[<span style="color:#a31515;">&quot;CategorySEOTabVisibility&quot;</span>]) || <span style="color:#2b91af;">NopContext</span>.Current.User.IsSuperAdmin);</pre>
<p>For another instance, if we wish to not hide the “Customer Enter Price” checkbox in product variant editing page because the business just will never allow customers to enter their own price, we can do the following in <strong>~/Administration/Modules/ProductVariantInfo.ascx.</strong> </p>
<pre class="code"><span style="background:yellow;">&lt;%</span> <span style="color:blue;">if </span>(!NopSolutions.NopCommerce.BusinessLogic.Configuration.<span style="color:#2b91af;">NopConfig</span>.AdminSettings.ContainsKey(<span style="color:#a31515;">&quot;ProductVariantCustomerEnterPriceCheckboxVisibility&quot;</span>) ||
           <span style="color:#2b91af;">Boolean</span>.Parse(NopSolutions.NopCommerce.BusinessLogic.Configuration.<span style="color:#2b91af;">NopConfig</span>.AdminSettings[<span style="color:#a31515;">&quot;ProductVariantCustomerEnterPriceCheckboxVisibility&quot;</span>]) ||
           <span style="color:#2b91af;">NopContext</span>.Current.User.IsSuperAdmin)
       {<span style="background:yellow;">%&gt;
</span>    <span style="color:blue;">&lt;</span><span style="color:maroon;">tr</span><span style="color:blue;">&gt;
        &lt;</span><span style="color:maroon;">td </span><span style="color:red;">class</span><span style="color:blue;">=&quot;adminTitle&quot;&gt;
            &lt;</span><span style="color:maroon;">nopcommerce</span><span style="color:blue;">:</span><span style="color:maroon;">tooltiplabel </span><span style="color:red;">runat</span><span style="color:blue;">=&quot;server&quot; </span><span style="color:red;">id</span><span style="color:blue;">=&quot;lblCallForPrice&quot; </span><span style="color:red;">text</span><span style="color:blue;">=&quot;</span><span style="background:yellow;">&lt;%</span><span style="color:blue;"> $</span>NopResources:Admin.ProductVariantInfo.CallForPrice <span style="background:yellow;">%&gt;</span><span style="color:blue;">&quot;
                </span><span style="color:red;">tooltip</span><span style="color:blue;">=&quot;</span><span style="background:yellow;">&lt;%</span><span style="color:blue;"> $</span>NopResources:Admin.ProductVariantInfo.CallForPrice.Tooltip <span style="background:yellow;">%&gt;</span><span style="color:blue;">&quot; </span><span style="color:red;">tooltipimage</span><span style="color:blue;">=&quot;~/Administration/Common/ico-help.gif&quot; /&gt;
        &lt;/</span><span style="color:maroon;">td</span><span style="color:blue;">&gt;
        &lt;</span><span style="color:maroon;">td </span><span style="color:red;">class</span><span style="color:blue;">=&quot;adminData&quot;&gt;
            &lt;</span><span style="color:maroon;">asp</span><span style="color:blue;">:</span><span style="color:maroon;">CheckBox </span><span style="color:red;">ID</span><span style="color:blue;">=&quot;cbCallForPrice&quot; </span><span style="color:red;">runat</span><span style="color:blue;">=&quot;server&quot; </span><span style="color:red;">Checked</span><span style="color:blue;">=&quot;False&quot;&gt;&lt;/</span><span style="color:maroon;">asp</span><span style="color:blue;">:</span><span style="color:maroon;">CheckBox</span><span style="color:blue;">&gt;
        &lt;/</span><span style="color:maroon;">td</span><span style="color:blue;">&gt;
    &lt;/</span><span style="color:maroon;">tr</span><span style="color:blue;">&gt;
</span><span style="background:yellow;">&lt;%</span>} <span style="background:yellow;">%&gt;
</span></pre>
<p>&#160;</p>
<p>Hope this is useful! Feedbacks are welcome and maybe better ways to achieve such! </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/notionstudio.wordpress.com/195/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/notionstudio.wordpress.com/195/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/notionstudio.wordpress.com/195/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/notionstudio.wordpress.com/195/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/notionstudio.wordpress.com/195/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/notionstudio.wordpress.com/195/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/notionstudio.wordpress.com/195/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/notionstudio.wordpress.com/195/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/notionstudio.wordpress.com/195/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/notionstudio.wordpress.com/195/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/notionstudio.wordpress.com/195/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/notionstudio.wordpress.com/195/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/notionstudio.wordpress.com/195/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/notionstudio.wordpress.com/195/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=notionstudio.wordpress.com&amp;blog=14839848&amp;post=195&amp;subd=notionstudio&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://notionstudio.wordpress.com/2011/03/06/nopcommerce-superadmin-and-access-control/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/392dac9bbc3c8fea87e0533a51b59b37?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Slayter</media:title>
		</media:content>
	</item>
		<item>
		<title>Use ASP.NET 4 URL Routing in nopCommerce 2</title>
		<link>http://notionstudio.wordpress.com/2011/01/08/use-asp-net-4-url-routing-in-nopcommerce-2/</link>
		<comments>http://notionstudio.wordpress.com/2011/01/08/use-asp-net-4-url-routing-in-nopcommerce-2/#comments</comments>
		<pubDate>Sat, 08 Jan 2011 04:32:24 +0000</pubDate>
		<dc:creator>Slayter</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">https://notionstudio.wordpress.com/2011/01/08/use-asp-net-4-url-routing-in-nopcommerce-2/</guid>
		<description><![CDATA[The 9 steps in the previous post should have gotten the re-writing working, but there are also more that needs to be refined. The biggest change in the previous post was the use of SEName to retrieve category as opposed to CategoryId. This creates an additional manual step as when you insert a new category [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=notionstudio.wordpress.com&amp;blog=14839848&amp;post=194&amp;subd=notionstudio&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The 9 steps in the <a href="http://notionstudio.wordpress.com/2011/01/03/use-asp-net-4-url-routing-in-nopcommerce/" target="_blank">previous post</a> should have gotten the re-writing working, but there are also more that needs to be refined. The biggest change in the <a href="http://notionstudio.wordpress.com/2011/01/03/use-asp-net-4-url-routing-in-nopcommerce/" target="_blank">previous post</a> was the use of SEName to retrieve category as opposed to CategoryId. This creates an additional manual step as when you insert a new category you need to be sure to also input “Search engine friendly page name” in the SEO tab, otherwise that rewriting won’t work. </p>
<p>The original rewrite is already using a good method to generate nice SEO friendly names, why don’t we leverage that and always also insert the SEName when a new category is added? Only one thing to do:</p>
<p>In <strong>NopCommerceStore.Administration.Modules.CategoryAdd.ascx.cs</strong>, which contains the 4 tabs used in creating a new category, before save to database happens we get the Name field in the Category Info tab, call the helper function to generate the SEO friendly name, and fill in the SEName textbox in the SEO tab. I have to say, <strong>FindControl</strong> is so ASP.NET WebForm, haha… </p>
<pre class="code"><span style="color:blue;">protected </span><span style="color:#2b91af;">Category </span>Save()
{
<span style="color:#2b91af;">    SimpleTextBox </span>nameTextBox = ((<span style="color:#2b91af;">SimpleTextBox</span>)ctrlCategoryInfo.FindControl(<span style="color:#a31515;">&quot;txtName&quot;</span>));
    <span style="color:blue;">if </span>(nameTextBox != <span style="color:blue;">null</span>)
    {
        <span style="color:blue;">string </span>catName = nameTextBox.Text;
        <span style="color:#2b91af;">TextBox </span>seNameTextBox = ((<span style="color:#2b91af;">TextBox</span>)ctrlCategorySEO.FindControl(<span style="color:#a31515;">&quot;txtSEName&quot;</span>));
        <span style="color:blue;">if </span>(seNameTextBox != <span style="color:blue;">null</span>)
        {
            <span style="color:blue;">string </span>seName = seNameTextBox.Text;
            <span style="color:blue;">if </span>(<span style="color:blue;">string</span>.IsNullOrWhiteSpace(seName))
            {
                seNameTextBox.Text = NopSolutions.NopCommerce.BusinessLogic.SEO.<span style="color:#2b91af;">SEOHelper</span>.GetSEName(catName);
            }
        }
    }</pre>
<p>Further to this topic I guess what we could do is to ensure that the SEName column is always unique. That’s a bigger change to the Database and the Entity context. </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/notionstudio.wordpress.com/194/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/notionstudio.wordpress.com/194/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/notionstudio.wordpress.com/194/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/notionstudio.wordpress.com/194/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/notionstudio.wordpress.com/194/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/notionstudio.wordpress.com/194/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/notionstudio.wordpress.com/194/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/notionstudio.wordpress.com/194/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/notionstudio.wordpress.com/194/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/notionstudio.wordpress.com/194/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/notionstudio.wordpress.com/194/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/notionstudio.wordpress.com/194/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/notionstudio.wordpress.com/194/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/notionstudio.wordpress.com/194/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=notionstudio.wordpress.com&amp;blog=14839848&amp;post=194&amp;subd=notionstudio&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://notionstudio.wordpress.com/2011/01/08/use-asp-net-4-url-routing-in-nopcommerce-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/392dac9bbc3c8fea87e0533a51b59b37?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Slayter</media:title>
		</media:content>
	</item>
		<item>
		<title>Use ASP.NET 4 URL Routing in nopCommerce</title>
		<link>http://notionstudio.wordpress.com/2011/01/03/use-asp-net-4-url-routing-in-nopcommerce/</link>
		<comments>http://notionstudio.wordpress.com/2011/01/03/use-asp-net-4-url-routing-in-nopcommerce/#comments</comments>
		<pubDate>Mon, 03 Jan 2011 05:31:21 +0000</pubDate>
		<dc:creator>Slayter</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">https://notionstudio.wordpress.com/2011/01/03/use-asp-net-4-url-routing-in-nopcommerce/</guid>
		<description><![CDATA[Note: in this discussion the nopCommerce version is 1.90 and it addresses only the product category page, not the product details page. In 1.90 the old Manager classes were re-named to Service classes, but beside such naming change, most of the inside logics remain intact (as far as this topic is concerned). nopCommerce by default [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=notionstudio.wordpress.com&amp;blog=14839848&amp;post=184&amp;subd=notionstudio&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Note: in this discussion the nopCommerce version is 1.90 and it addresses only the product category page, not the product details page. In 1.90 the old Manager classes were re-named to Service classes, but beside such naming change, most of the inside logics remain intact (as far as this topic is concerned).</p>
<p>nopCommerce by default uses the <a href="http://urlrewriting.net" target="_blank">UrlRewriting.NET</a> solution and it actually works wonderfully. The only thing that I don’t like about was having to include the CategoryID in the URL. For instance, if URLRewriting is turned on (you can do so in Admin&gt;Global Settings&gt;SEO), you get <strong>~/category/{id}-{sename}.aspx</strong> as your URL (Or whatever format you prefer, just that you can’t avoid having the {id} in the URL, which seems annoying to me.)</p>
<p>We can, however, construct a nice, SEO-friendly URL step by step:</p>
<p>1. Add the <strong>UrlRoutingModule</strong> to web.config</p>
<p>2. Disable the <strong>UrlRewriteModule</strong> from web.config</p>
<p>3. Make sure <strong>runAllManagedModulesForAllRequests</strong> is set to true</p>
<p>Here’s the <strong>&lt;system.webServer&gt;</strong> node in web.config highlighting steps 1 &#8211; 3</p>
<pre class="code"><span style="color:blue;">&lt;</span><span style="color:#a31515;">system.webServer</span><span style="color:blue;">&gt;
    &lt;</span><span style="color:#a31515;">validation </span><span style="color:red;">validateIntegratedModeConfiguration</span><span style="color:blue;">=</span>"<span style="color:blue;">false</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>"<span style="color:blue;">true</span>"<span style="color:blue;">&gt;
        &lt;</span><span style="color:#a31515;">remove </span><span style="color:red;">name</span><span style="color:blue;">=</span>"<span style="color:blue;">NopCommerceFilter</span>" <span style="color:blue;">/&gt;
        &lt;</span><span style="color:#a31515;">remove </span><span style="color:red;">name</span><span style="color:blue;">=</span>"<span style="color:blue;">UrlRewriteModule</span>" <span style="color:blue;">/&gt;
        &lt;</span><span style="color:#a31515;">add </span><span style="color:red;">name</span><span style="color:blue;">=</span>"<span style="color:blue;">MembershipHttpModule</span>" <span style="color:red;">preCondition</span><span style="color:blue;">=</span>"<span style="color:blue;">managedHandler</span>" <span style="color:red;">type</span><span style="color:blue;">=</span>"<span style="color:blue;">NopSolutions.NopCommerce.BusinessLogic.Profile.MembershipHttpModule, Nop.BusinessLogic</span>" <span style="color:blue;">/&gt;            
</span><span style="color:#0000ff;"><span style="color:blue;">        &lt;!--</span><span style="color:green;">&lt;add name="UrlRewriteModule" preCondition="managedHandler" type="UrlRewritingNet.Web.UrlRewriteModule, UrlRewritingNet.UrlRewriter" /&gt;</span><span style="color:blue;">--&gt;
</span></span><span style="color:blue;">        &lt;</span><span style="color:#a31515;">add </span><span style="color:red;">name</span><span style="color:blue;">=</span>"<span style="color:blue;">BlacklistHttpModule</span>" <span style="color:red;">preCondition</span><span style="color:blue;">=</span>"<span style="color:blue;">managedHandler</span>" <span style="color:red;">type</span><span style="color:blue;">=</span>"<span style="color:blue;">NopSolutions.NopCommerce.BusinessLogic.Security.BlacklistHttpModule, Nop.BusinessLogic</span>" <span style="color:blue;">/&gt;
</span><span style="color:blue;">        &lt;</span><span style="color:#a31515;">add </span><span style="color:red;">name</span><span style="color:blue;">=</span>"<span style="color:blue;">UrlRoutingModule</span>" <span style="color:red;">type</span><span style="color:blue;">=</span>"<span style="color:blue;">System.Web.Routing.UrlRoutingModule, System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35</span>" <span style="color:blue;">/&gt;
</span><span style="color:blue;">    &lt;/</span><span style="color:#a31515;">modules</span><span style="color:blue;">&gt;
</span><span style="color:blue;">    &lt;</span><span style="color:#a31515;">handlers</span><span style="color:blue;">&gt;
</span><span style="color:blue;">        &lt;</span><span style="color:#a31515;">add </span><span style="color:red;">name</span><span style="color:blue;">=</span>"<span style="color:blue;">ChartImageHandler</span>" <span style="color:red;">preCondition</span><span style="color:blue;">=</span>"<span style="color:blue;">integratedMode</span>" <span style="color:red;">verb</span><span style="color:blue;">=</span>"<span style="color:blue;">GET,HEAD,POST</span>" <span style="color:red;">path</span><span style="color:blue;">=</span>"<span style="color:blue;">ChartImg.axd</span>" <span style="color:red;">type</span><span style="color:blue;">=</span>"<span style="color:blue;">System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35</span>" <span style="color:blue;">/&gt;
</span><span style="color:blue;">        &lt;</span><span style="color:#a31515;">add </span><span style="color:red;">name</span><span style="color:blue;">=</span>"<span style="color:blue;">PricelistHandler</span>" <span style="color:red;">verb</span><span style="color:blue;">=</span>"<span style="color:blue;">*</span>" <span style="color:red;">path</span><span style="color:blue;">=</span>"<span style="color:blue;">pricelist.csv</span>" <span style="color:red;">preCondition</span><span style="color:blue;">=</span>"<span style="color:blue;">integratedMode</span>" <span style="color:red;">type</span><span style="color:blue;">=</span>"<span style="color:blue;">NopSolutions.NopCommerce.BusinessLogic.ExportImport.PricelistHandler, Nop.BusinessLogic</span>" <span style="color:blue;">/&gt;
</span><span style="color:blue;">        &lt;</span><span style="color:#a31515;">add </span><span style="color:red;">name</span><span style="color:blue;">=</span>"<span style="color:blue;">UrlRoutingHandler</span>" <span style="color:red;">preCondition</span><span style="color:blue;">=</span>"<span style="color:blue;">integratedMode</span>" <span style="color:red;">verb</span><span style="color:blue;">=</span>"<span style="color:blue;">*</span>" <span style="color:red;">path</span><span style="color:blue;">=</span>"<span style="color:blue;">UrlRouting.axd</span>" <span style="color:red;">type</span><span style="color:blue;">=</span>"<span style="color:blue;">System.Web.HttpForbiddenHandler,System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</span>" <span style="color:blue;">/&gt;
</span><span style="color:blue;"><span style="color:#0000ff;">    </span>&lt;/</span><span style="color:#a31515;">handlers</span><span style="color:blue;">&gt;
</span><span style="color:blue;">&lt;/</span><span style="color:#a31515;">system.webServer</span><span style="color:blue;">&gt;</span></pre>
<p>4. Update how the category URL is constructed in  <strong>NopSolutions.NopCommerce.BusinessLogic.SEO</strong>.<strong>GetCategoryUrl(Category category)</strong></p>
<pre class="code"><span style="color:blue;">string </span>url2 = <span style="color:#a31515;">"{0}shop/{1}"</span>;
<span style="color:blue;">string</span>url = <span style="color:blue;">string</span>.Format(url2, <span style="color:#2b91af;">CommonHelper</span>.GetStoreLocation(), seName);
<span style="color:blue;">return</span>url.ToLowerInvariant();</pre>
<p>which means Enabling URL Rewriting or not will yield the same result (We do want to enforce the SEO-friendly URL). Note that the CategoryId is no longer in the URL. <strong>shop</strong> in the example above is just the hardcoded piece of the path so it could be anything.</p>
<p>5.  Make sure that the web app has reference to <strong>System.Web.Routing</strong> assembly</p>
<p>6. Add the routing map to <strong>Global.asax</strong> so now we can have a URL that looks something like  <a href="http://yourstore.com/shop/electronics">http://yourstore.com/shop/electronics</a> and the application will know to redirect it to Category.aspx</p>
<pre class="code">
void RegisterRoutes(System.Web.Routing.RouteCollection routes)
{
    routes.MapPageRoute(
        <span style="color:#a31515;"> "category-browse"</span>,       <span style="color:green;">// Route name </span>
        <span style="color:#a31515;"> "shop/{SEName}"</span>,         <span style="color:green;">// URL  </span>
        <span style="color:#a31515;"> "~/Category.aspx" </span><span style="color:green;">// Web Forms page  </span>
    );
}
</pre>
<pre class="code"><span style="color:blue;">void </span>Application_Start(<span style="color:blue;">object </span>sender, <span style="color:#2b91af;">EventArgs </span>e)
{
    RegisterRoutes(System.Web.Routing.<span style="color:#2b91af;">RouteTable</span>.Routes);    …</pre>
<p>7. Add a method called <strong>GetCategoryBySEName(string seName)</strong> to <strong>ICategoryService</strong> &amp; <strong>CategoryService</strong>. We need this because the URL no longer contains the CategoryId so we will need to retrieve the Category using SEName.</p>
<pre class="code"><span style="color:gray;">/// &lt;summary&gt;
/// </span><span style="color:green;">Gets a category
</span><span style="color:gray;">/// &lt;/summary&gt;
/// &lt;param name="seName"&gt;</span><span style="color:green;">Search engine friendly name of the category</span><span style="color:gray;">&lt;/param&gt;
/// &lt;returns&gt;</span><span style="color:green;">Category</span><span style="color:gray;">&lt;/returns&gt;
</span><span style="color:blue;">public </span><span style="color:#2b91af;">Category </span>GetCategoryBySEName(<span style="color:blue;">string </span>seName)
{
<span style="color:blue;">    if </span>(<span style="color:blue;">string</span>.IsNullOrWhiteSpace(seName))
    {
        <span style="color:blue;">return null</span>;
    }

    <span style="color:blue;">string </span>key = <span style="color:blue;">string</span>.Format(CATEGORIES_BY_SENAME, seName);
    <span style="color:blue;">object </span>obj2 = _cacheManager.Get(key);
    <span style="color:blue;">if </span>(<span style="color:blue;">this</span>.CategoriesCacheEnabled &amp;&amp; (obj2 != <span style="color:blue;">null</span>))
    {
        <span style="color:blue;">return </span>(<span style="color:#2b91af;">Category</span>)obj2;
    }

    <span style="color:blue;">bool </span>showHidden = <span style="color:#2b91af;">NopContext</span>.Current.IsAdmin;

    <span style="color:blue;">var </span>query = <span style="color:blue;">from </span>c <span style="color:blue;">in </span>_context.Categories
                <span style="color:blue;">where </span>c.SEName == seName
                <span style="color:blue;">select </span>c;
    <span style="color:#2b91af;">Category </span>category = query.FirstOrDefault();

    <span style="color:green;">//filter by access control list (public store)
    </span><span style="color:blue;">if </span>(category != <span style="color:blue;">null </span>&amp;&amp; !showHidden &amp;&amp; IsCategoryAccessDenied(category))
    {
        category = <span style="color:blue;">null</span>;
    }
    <span style="color:blue;">if </span>(<span style="color:blue;">this</span>.CategoriesCacheEnabled)
    {
        _cacheManager.Add(key, category);
    }

    <span style="color:blue;">return </span>category;
}</pre>
<p>8. Update in Category.aspx to retrieve the category using the nice URL. ~/shop/electronics</p>
<p>The first line of the <strong>CreateChildControlTree()</strong> method it calls <strong>CategoryService’s</strong> <strong>GetCategoryById</strong>. Now we need to use <strong>GetCategoryBySEName</strong> that we just added above.</p>
<pre class="code"><span style="color:blue;">private void </span>CreateChildControlsTree()
{
    category = <span style="color:blue;">this</span>.CategoryService.GetCategoryBySEName(<span style="color:blue;">this</span>.SEName);</pre>
<p>To do that, we need to change the SEName property to get the value from <strong>RouteData</strong>, not query string.</p>
<pre class="code"><span style="color:blue;">public string </span>SEName
{
<span style="color:blue;">    get
    </span>{
        <span style="color:blue;">return </span>Page.RouteData.Values[<span style="color:#a31515;">"SEName"</span>] <span style="color:blue;">as string</span>;
    }
}</pre>
<p>9. Update the same in your product templates as well. If there is no <strong>SEName</strong> property in the product templates, add the one like in Step 8. In the method <strong>BindData()</strong> is where it references a lot to the category, so I’ve created a private variable to hold the Category object that I will retrieve using SEName,</p>
<pre class="code"><span style="color:blue;">public partial class </span><span style="color:#2b91af;">ProductsInGrid</span>: <span style="color:#2b91af;">BaseNopFrontendUserControl
</span>{
    <span style="color:blue;">private </span><span style="color:#2b91af;">Category </span>_category = <span style="color:blue;">null</span>;</pre>
<pre class="code"><span style="color:blue;">protected void </span>BindData()
{
    _category = <span style="color:blue;">this</span>.CategoryService.GetCategoryBySEName(<span style="color:blue;">this</span>.SEName);</pre>
<p>After you complete all 9 steps here, you should be all set and have a very nice SEO-friendly URL for your nopCommerce store.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/notionstudio.wordpress.com/184/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/notionstudio.wordpress.com/184/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/notionstudio.wordpress.com/184/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/notionstudio.wordpress.com/184/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/notionstudio.wordpress.com/184/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/notionstudio.wordpress.com/184/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/notionstudio.wordpress.com/184/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/notionstudio.wordpress.com/184/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/notionstudio.wordpress.com/184/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/notionstudio.wordpress.com/184/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/notionstudio.wordpress.com/184/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/notionstudio.wordpress.com/184/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/notionstudio.wordpress.com/184/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/notionstudio.wordpress.com/184/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=notionstudio.wordpress.com&amp;blog=14839848&amp;post=184&amp;subd=notionstudio&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://notionstudio.wordpress.com/2011/01/03/use-asp-net-4-url-routing-in-nopcommerce/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/392dac9bbc3c8fea87e0533a51b59b37?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Slayter</media:title>
		</media:content>
	</item>
		<item>
		<title>Consume RESTful Web Services in C#</title>
		<link>http://notionstudio.wordpress.com/2010/11/28/consume-restful-web-services-in-c/</link>
		<comments>http://notionstudio.wordpress.com/2010/11/28/consume-restful-web-services-in-c/#comments</comments>
		<pubDate>Sun, 28 Nov 2010 23:08:20 +0000</pubDate>
		<dc:creator>Slayter</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">https://notionstudio.wordpress.com/2010/11/28/consume-restful-web-services-in-c/</guid>
		<description><![CDATA[The acronym REST stands for Representational State Transfer, this basically means that each unique URL is a representation of some object. It embraces a stateless client-server architecture in which the web services are viewed as resources and can be identified by their URLs. It’s different from the more traditional SOAP. Not gonna go into the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=notionstudio.wordpress.com&amp;blog=14839848&amp;post=181&amp;subd=notionstudio&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The acronym REST stands for <strong>Representational State Transfer</strong>, this basically means that each unique URL is a representation of some object. It embraces a stateless client-server architecture in which the web services are viewed as resources and can be identified by their URLs. It’s different from the more traditional SOAP. Not gonna go into the details of the differences between the two as it will be endless. This link from AjaxPatterns has a pretty in-depth explanation of RESTful services. </p>
<p><a title="http://ajaxpatterns.org/RESTful_Service" href="http://ajaxpatterns.org/RESTful_Service">http://ajaxpatterns.org/RESTful_Service</a></p>
<p>There are many ways to consume a RESTful service in C#. Since all it needs is the URL we can create an Http Web Request and then process the response. Another way is to use the more advanced WCF, which I’ve came across this link here:</p>
<p><a title="http://blogs.msdn.com/b/pedram/archive/2008/04/21/how-to-consume-rest-services-with-wcf.aspx" href="http://blogs.msdn.com/b/pedram/archive/2008/04/21/how-to-consume-rest-services-with-wcf.aspx">http://blogs.msdn.com/b/pedram/archive/2008/04/21/how-to-consume-rest-services-with-wcf.aspx</a></p>
<p>It’s very good as it uses WCF to do the serialization and it eliminates the need to do manual transformation. But as always, you don’t get nothing for free. In this case it’s the same as all other situations when you let the framework do your dirty laundry &#8211; you lost flexibility. In addition, it might be hard for someone viewing your code to fully understand what’s going on right away because some stuff is in the web.config, some in code, and some in attributes. </p>
<p>A lot of the publicly available RESTful web services, such as Google Map API, Flicker’s API, Bing platform’s services, support both JSON and XML format. In the JavaScript world I prefer JSON, but when it comes to C# I still find XML much easier to work with for the simple fact that LINQ to XML is right at your fingertip. </p>
<p>Therefore, I find that using LINQ to XML and XPath transformation is pretty easy to consume a RESTful services and extract the information that you need. I am using Google Map API as an example here:</p>
<div style="border-bottom:silver 1px solid;text-align:left;border-left:silver 1px solid;line-height:12pt;background-color:#f4f4f4;width:97.5%;font-family:&#039;direction:ltr;max-height:200px;font-size:8pt;overflow:auto;border-top:silver 1px solid;cursor:text;border-right:silver 1px solid;margin:20px 0 10px;padding:4px;" id="codeSnippetWrapper">
<div style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#039;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;padding:0;" id="codeSnippet">
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#039;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum1">   1:</span> XElement root = XElement.Load(<span style="color:#006080;">&quot;http://maps.googleapis.com/maps/api/geocode/xml?sensor=false&amp;address=Toronto&quot;</span>);</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#039;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum2">   2:</span> <span style="color:#0000ff;">if</span> (<span style="color:#0000ff;">decimal</span>.TryParse(root.XPathSelectElement(<span style="color:#006080;">&quot;//result//geometry//location//lat&quot;</span>).Value, <span style="color:#0000ff;">out</span> latitude) &amp;&amp; </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#039;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum3">   3:</span>     <span style="color:#0000ff;">decimal</span>.TryParse(root.XPathSelectElement(<span style="color:#006080;">&quot;//result//geometry//location//lat&quot;</span>).Value, <span style="color:#0000ff;">out</span> longitude))</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#039;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum4">   4:</span> {</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#039;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum5">   5:</span>     result.Add(<span style="color:#0000ff;">new</span> BusinessObjects.Location</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#039;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum6">   6:</span>     {</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#039;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum7">   7:</span>         Coordinate = <span style="color:#0000ff;">new</span> BusinessObjects.LatLng { Latitude = latitude, Longitude = longitude },</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#039;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum8">   8:</span>         FormattedAddress = root.XPathSelectElement(<span style="color:#006080;">&quot;//result//geometry//location//lat&quot;</span>).Value,</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;font-family:&#039;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum9">   9:</span>     });</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#039;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum10">  10:</span> }</pre>
<p><!--CRLF--></div>
</div>
<p>As you can see, only a few lines of code. I am calling Google Map’s geocoding service and looking for Toronto. As soon as I have loaded the response XML into XElement I used XPath to get the latitude and longitude, as well as the formatted address in order to construct my own Location object, which might then contain other business logics and validation requirements specific to my application. </p>
<p>Well, that’s it. Here’s the XML response of the link above:</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:red;">encoding</span><span style="color:blue;">=</span>&quot;<span style="color:blue;">utf-8</span>&quot; <span style="color:blue;">?&gt;
&lt;</span><span style="color:#a31515;">GeocodeResponse</span><span style="color:blue;">&gt;
    &lt;</span><span style="color:#a31515;">status</span><span style="color:blue;">&gt;</span>OK<span style="color:blue;">&lt;/</span><span style="color:#a31515;">status</span><span style="color:blue;">&gt;
    &lt;</span><span style="color:#a31515;">result</span><span style="color:blue;">&gt;
        &lt;</span><span style="color:#a31515;">type</span><span style="color:blue;">&gt;</span>locality<span style="color:blue;">&lt;/</span><span style="color:#a31515;">type</span><span style="color:blue;">&gt;
        &lt;</span><span style="color:#a31515;">type</span><span style="color:blue;">&gt;</span>political<span style="color:blue;">&lt;/</span><span style="color:#a31515;">type</span><span style="color:blue;">&gt;
        &lt;</span><span style="color:#a31515;">formatted_address</span><span style="color:blue;">&gt;</span>Toronto, ON, Canada<span style="color:blue;">&lt;/</span><span style="color:#a31515;">formatted_address</span><span style="color:blue;">&gt;
        &lt;</span><span style="color:#a31515;">address_component</span><span style="color:blue;">&gt;
            &lt;</span><span style="color:#a31515;">long_name</span><span style="color:blue;">&gt;</span>Toronto<span style="color:blue;">&lt;/</span><span style="color:#a31515;">long_name</span><span style="color:blue;">&gt;
            &lt;</span><span style="color:#a31515;">short_name</span><span style="color:blue;">&gt;</span>Toronto<span style="color:blue;">&lt;/</span><span style="color:#a31515;">short_name</span><span style="color:blue;">&gt;
            &lt;</span><span style="color:#a31515;">type</span><span style="color:blue;">&gt;</span>locality<span style="color:blue;">&lt;/</span><span style="color:#a31515;">type</span><span style="color:blue;">&gt;
            &lt;</span><span style="color:#a31515;">type</span><span style="color:blue;">&gt;</span>political<span style="color:blue;">&lt;/</span><span style="color:#a31515;">type</span><span style="color:blue;">&gt;
        &lt;/</span><span style="color:#a31515;">address_component</span><span style="color:blue;">&gt;
        &lt;</span><span style="color:#a31515;">address_component</span><span style="color:blue;">&gt;
            &lt;</span><span style="color:#a31515;">long_name</span><span style="color:blue;">&gt;</span>Toronto Division<span style="color:blue;">&lt;/</span><span style="color:#a31515;">long_name</span><span style="color:blue;">&gt;
            &lt;</span><span style="color:#a31515;">short_name</span><span style="color:blue;">&gt;</span>Toronto Division<span style="color:blue;">&lt;/</span><span style="color:#a31515;">short_name</span><span style="color:blue;">&gt;
            &lt;</span><span style="color:#a31515;">type</span><span style="color:blue;">&gt;</span>administrative_area_level_2<span style="color:blue;">&lt;/</span><span style="color:#a31515;">type</span><span style="color:blue;">&gt;
            &lt;</span><span style="color:#a31515;">type</span><span style="color:blue;">&gt;</span>political<span style="color:blue;">&lt;/</span><span style="color:#a31515;">type</span><span style="color:blue;">&gt;
        &lt;/</span><span style="color:#a31515;">address_component</span><span style="color:blue;">&gt;
        &lt;</span><span style="color:#a31515;">address_component</span><span style="color:blue;">&gt;
            &lt;</span><span style="color:#a31515;">long_name</span><span style="color:blue;">&gt;</span>Ontario<span style="color:blue;">&lt;/</span><span style="color:#a31515;">long_name</span><span style="color:blue;">&gt;
            &lt;</span><span style="color:#a31515;">short_name</span><span style="color:blue;">&gt;</span>ON<span style="color:blue;">&lt;/</span><span style="color:#a31515;">short_name</span><span style="color:blue;">&gt;
            &lt;</span><span style="color:#a31515;">type</span><span style="color:blue;">&gt;</span>administrative_area_level_1<span style="color:blue;">&lt;/</span><span style="color:#a31515;">type</span><span style="color:blue;">&gt;
            &lt;</span><span style="color:#a31515;">type</span><span style="color:blue;">&gt;</span>political<span style="color:blue;">&lt;/</span><span style="color:#a31515;">type</span><span style="color:blue;">&gt;
        &lt;/</span><span style="color:#a31515;">address_component</span><span style="color:blue;">&gt;
        &lt;</span><span style="color:#a31515;">address_component</span><span style="color:blue;">&gt;
            &lt;</span><span style="color:#a31515;">long_name</span><span style="color:blue;">&gt;</span>Canada<span style="color:blue;">&lt;/</span><span style="color:#a31515;">long_name</span><span style="color:blue;">&gt;
            &lt;</span><span style="color:#a31515;">short_name</span><span style="color:blue;">&gt;</span>CA<span style="color:blue;">&lt;/</span><span style="color:#a31515;">short_name</span><span style="color:blue;">&gt;
            &lt;</span><span style="color:#a31515;">type</span><span style="color:blue;">&gt;</span>country<span style="color:blue;">&lt;/</span><span style="color:#a31515;">type</span><span style="color:blue;">&gt;
            &lt;</span><span style="color:#a31515;">type</span><span style="color:blue;">&gt;</span>political<span style="color:blue;">&lt;/</span><span style="color:#a31515;">type</span><span style="color:blue;">&gt;
        &lt;/</span><span style="color:#a31515;">address_component</span><span style="color:blue;">&gt;
        &lt;</span><span style="color:#a31515;">geometry</span><span style="color:blue;">&gt;
            &lt;</span><span style="color:#a31515;">location</span><span style="color:blue;">&gt;
                &lt;</span><span style="color:#a31515;">lat</span><span style="color:blue;">&gt;</span>43.6525000<span style="color:blue;">&lt;/</span><span style="color:#a31515;">lat</span><span style="color:blue;">&gt;
                &lt;</span><span style="color:#a31515;">lng</span><span style="color:blue;">&gt;</span>-79.3816667<span style="color:blue;">&lt;/</span><span style="color:#a31515;">lng</span><span style="color:blue;">&gt;
            &lt;/</span><span style="color:#a31515;">location</span><span style="color:blue;">&gt;
            &lt;</span><span style="color:#a31515;">location_type</span><span style="color:blue;">&gt;</span>APPROXIMATE<span style="color:blue;">&lt;/</span><span style="color:#a31515;">location_type</span><span style="color:blue;">&gt;
            &lt;</span><span style="color:#a31515;">viewport</span><span style="color:blue;">&gt;
                &lt;</span><span style="color:#a31515;">southwest</span><span style="color:blue;">&gt;
                    &lt;</span><span style="color:#a31515;">lat</span><span style="color:blue;">&gt;</span>43.5231891<span style="color:blue;">&lt;/</span><span style="color:#a31515;">lat</span><span style="color:blue;">&gt;
                    &lt;</span><span style="color:#a31515;">lng</span><span style="color:blue;">&gt;</span>-79.6377855<span style="color:blue;">&lt;/</span><span style="color:#a31515;">lng</span><span style="color:blue;">&gt;
                &lt;/</span><span style="color:#a31515;">southwest</span><span style="color:blue;">&gt;
                &lt;</span><span style="color:#a31515;">northeast</span><span style="color:blue;">&gt;
                    &lt;</span><span style="color:#a31515;">lat</span><span style="color:blue;">&gt;</span>43.7815330<span style="color:blue;">&lt;/</span><span style="color:#a31515;">lat</span><span style="color:blue;">&gt;
                    &lt;</span><span style="color:#a31515;">lng</span><span style="color:blue;">&gt;</span>-79.1255479<span style="color:blue;">&lt;/</span><span style="color:#a31515;">lng</span><span style="color:blue;">&gt;
                &lt;/</span><span style="color:#a31515;">northeast</span><span style="color:blue;">&gt;
            &lt;/</span><span style="color:#a31515;">viewport</span><span style="color:blue;">&gt;
            &lt;</span><span style="color:#a31515;">bounds</span><span style="color:blue;">&gt;
                &lt;</span><span style="color:#a31515;">southwest</span><span style="color:blue;">&gt;
                    &lt;</span><span style="color:#a31515;">lat</span><span style="color:blue;">&gt;</span>43.4582970<span style="color:blue;">&lt;/</span><span style="color:#a31515;">lat</span><span style="color:blue;">&gt;
                    &lt;</span><span style="color:#a31515;">lng</span><span style="color:blue;">&gt;</span>-79.6392190<span style="color:blue;">&lt;/</span><span style="color:#a31515;">lng</span><span style="color:blue;">&gt;
                &lt;/</span><span style="color:#a31515;">southwest</span><span style="color:blue;">&gt;
                &lt;</span><span style="color:#a31515;">northeast</span><span style="color:blue;">&gt;
                    &lt;</span><span style="color:#a31515;">lat</span><span style="color:blue;">&gt;</span>43.8554580<span style="color:blue;">&lt;/</span><span style="color:#a31515;">lat</span><span style="color:blue;">&gt;
                    &lt;</span><span style="color:#a31515;">lng</span><span style="color:blue;">&gt;</span>-79.0024810<span style="color:blue;">&lt;/</span><span style="color:#a31515;">lng</span><span style="color:blue;">&gt;
                &lt;/</span><span style="color:#a31515;">northeast</span><span style="color:blue;">&gt;
            &lt;/</span><span style="color:#a31515;">bounds</span><span style="color:blue;">&gt;
        &lt;/</span><span style="color:#a31515;">geometry</span><span style="color:blue;">&gt;
    &lt;/</span><span style="color:#a31515;">result</span><span style="color:blue;">&gt;
&lt;/</span><span style="color:#a31515;">GeocodeResponse</span><span style="color:blue;">&gt;
</span></pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/notionstudio.wordpress.com/181/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/notionstudio.wordpress.com/181/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/notionstudio.wordpress.com/181/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/notionstudio.wordpress.com/181/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/notionstudio.wordpress.com/181/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/notionstudio.wordpress.com/181/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/notionstudio.wordpress.com/181/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/notionstudio.wordpress.com/181/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/notionstudio.wordpress.com/181/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/notionstudio.wordpress.com/181/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/notionstudio.wordpress.com/181/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/notionstudio.wordpress.com/181/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/notionstudio.wordpress.com/181/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/notionstudio.wordpress.com/181/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=notionstudio.wordpress.com&amp;blog=14839848&amp;post=181&amp;subd=notionstudio&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://notionstudio.wordpress.com/2010/11/28/consume-restful-web-services-in-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/392dac9bbc3c8fea87e0533a51b59b37?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Slayter</media:title>
		</media:content>
	</item>
		<item>
		<title>Removing and adding event handlers using reflection</title>
		<link>http://notionstudio.wordpress.com/2010/09/17/removing-and-adding-event-handlers-using-reflection/</link>
		<comments>http://notionstudio.wordpress.com/2010/09/17/removing-and-adding-event-handlers-using-reflection/#comments</comments>
		<pubDate>Fri, 17 Sep 2010 13:38:40 +0000</pubDate>
		<dc:creator>Raymond Tsang</dc:creator>
				<category><![CDATA[C# Programming]]></category>
		<category><![CDATA[Event Handler]]></category>
		<category><![CDATA[Reflection]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://notionstudio.wordpress.com/?p=161</guid>
		<description><![CDATA[Recently I ran into an situation that I need to remove all the event handlers, perform some work and then re-attach all the event handlers.  This requires using reflection since we need to discover the event handler in runtime. This is useful in cases where the object itself do not have knowledge of who has [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=notionstudio.wordpress.com&amp;blog=14839848&amp;post=161&amp;subd=notionstudio&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Recently I ran into an situation that I need to remove all the event handlers, perform some work and then re-attach all the event handlers.  This requires using reflection since we need to discover the event handler in runtime. This is useful in cases where the object itself do not have knowledge of who has attached to itself. </p>
<p>The code is listed just below.  We need the FieldInfo so that we can call GetValue() to get a reference to the event delegate.  Then using EventInfo.RemoveEventHandler() and EventInfo.AddEventHandler() to detach and re-attach the handler:</p>
<p><code><br />
// define the binding flags for reflection<br />
var bindingFlags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance;</p>
<p>// Target has a event call PropertyChanged<br />
Type type = target.GetType();<br />
var fieldInfo = type.GetField("PropertyChanged", bindingFlags);<br />
var eventInfo = type.GetEvent("PropertyChanged", bindingFlags);</p>
<p>// using GetValue() to get the reference of event delegate<br />
var del = fieldInfo.GetValue(target) as Delegate;</p>
<p>// detach the event handler<br />
if (del != null)<br />
  eventInfo.RemoveEventHandler(target, del);</p>
<p>// Do you thing here!!</p>
<p>// re-attach the event handler<br />
if (del != null)<br />
  eventInfo.AddEventHandler(target, del);</p>
<p></code></p>
<p>Simple enough?  We can further improve this by looping through all the events and fields, so we don&#8217;t need the hardcoded event name in string.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/notionstudio.wordpress.com/161/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/notionstudio.wordpress.com/161/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/notionstudio.wordpress.com/161/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/notionstudio.wordpress.com/161/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/notionstudio.wordpress.com/161/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/notionstudio.wordpress.com/161/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/notionstudio.wordpress.com/161/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/notionstudio.wordpress.com/161/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/notionstudio.wordpress.com/161/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/notionstudio.wordpress.com/161/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/notionstudio.wordpress.com/161/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/notionstudio.wordpress.com/161/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/notionstudio.wordpress.com/161/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/notionstudio.wordpress.com/161/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=notionstudio.wordpress.com&amp;blog=14839848&amp;post=161&amp;subd=notionstudio&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://notionstudio.wordpress.com/2010/09/17/removing-and-adding-event-handlers-using-reflection/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/5553e49ca6fc1626ca53e4971308601d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">tsanglwr</media:title>
		</media:content>
	</item>
		<item>
		<title>WCF 403 Forbidden Exception</title>
		<link>http://notionstudio.wordpress.com/2009/11/26/wcf-403-forbidden-exception/</link>
		<comments>http://notionstudio.wordpress.com/2009/11/26/wcf-403-forbidden-exception/#comments</comments>
		<pubDate>Fri, 27 Nov 2009 02:36:45 +0000</pubDate>
		<dc:creator>Slayter</dc:creator>
				<category><![CDATA[ASP.NET]]></category>

		<guid isPermaLink="false">http://wikiaspnet.wordpress.com/2009/11/26/wcf-403-forbidden-exception/</guid>
		<description><![CDATA[WCF (Windows Communication Foundation) comes with .NET 2.0, and with JSON serialization format with .NET 3.5. The most important DLL is ServiceModel. The thing is, when installing the .NET framework, it doesn’t mean that ServiceModel is registered with your server, or in particular, with IIS. If that’s the case, you will most likely get the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=notionstudio.wordpress.com&amp;blog=14839848&amp;post=141&amp;subd=notionstudio&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://msdn.microsoft.com/en-us/netframework/aa663324.aspx" target="_blank">WCF (Windows Communication Foundation)</a> comes with .NET 2.0, and with JSON serialization format with .NET 3.5. The most important DLL is ServiceModel. The thing is, when installing the .NET framework, it doesn’t mean that ServiceModel is registered with your server, or in particular, with IIS. </p>
<p>If that’s the case, you will most likely get the error below:</p>
<blockquote><p><font color="#804040">An existing connection was forcibly closed by the remote host.</font></p>
<p><font color="#804040">The remote server returned an error: (403) Forbidden.</font></p>
<p><font color="#804040">The HTTP request was forbidden with client authentication scheme &#8216;Anonymous&#8217;.</font></p>
</blockquote>
<p>If that’s the case, you just need to register ServiceModel to your IIS using the <a href="http://msdn.microsoft.com/en-us/library/ms732012.aspx" target="_blank">ServiceModelReg.exe</a> tool. =)</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/notionstudio.wordpress.com/141/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/notionstudio.wordpress.com/141/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/notionstudio.wordpress.com/141/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/notionstudio.wordpress.com/141/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/notionstudio.wordpress.com/141/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/notionstudio.wordpress.com/141/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/notionstudio.wordpress.com/141/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/notionstudio.wordpress.com/141/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/notionstudio.wordpress.com/141/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/notionstudio.wordpress.com/141/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/notionstudio.wordpress.com/141/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/notionstudio.wordpress.com/141/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/notionstudio.wordpress.com/141/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/notionstudio.wordpress.com/141/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=notionstudio.wordpress.com&amp;blog=14839848&amp;post=141&amp;subd=notionstudio&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://notionstudio.wordpress.com/2009/11/26/wcf-403-forbidden-exception/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/392dac9bbc3c8fea87e0533a51b59b37?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Slayter</media:title>
		</media:content>
	</item>
		<item>
		<title>ASP.NET Validation</title>
		<link>http://notionstudio.wordpress.com/2008/08/22/aspnet-validation/</link>
		<comments>http://notionstudio.wordpress.com/2008/08/22/aspnet-validation/#comments</comments>
		<pubDate>Fri, 22 Aug 2008 19:27:36 +0000</pubDate>
		<dc:creator>Slayter</dc:creator>
				<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://wikiaspnet.wordpress.com/?p=127</guid>
		<description><![CDATA[Validation is pretty essential for a web page with form submission. But even with all the help from Microsoft&#8217;s wonderful validation controls, at times some petty details becomes quite annoying problems to solve. This post is to list out some useful resources&#8230; Validating ASP.NET Server Controls http://msdn.microsoft.com/en-us/library/aa479013.aspx User Input Validation in ASP.NET http://msdn.microsoft.com/en-us/library/ms972961.aspx ASP.NET Validation [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=notionstudio.wordpress.com&amp;blog=14839848&amp;post=127&amp;subd=notionstudio&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Validation is pretty essential for a web page with form submission. But even with all the help from Microsoft&#8217;s wonderful validation controls, at times some petty details becomes quite annoying problems to solve. This post is to list out some useful resources&#8230;</p>
<p>Validating ASP.NET Server Controls<br />
<a href="//msdn.microsoft.com/en-us/library/aa479045.aspx" target="_blank">http://msdn.microsoft.com/en-us/library/aa479013.aspx</a><br />
User Input Validation in ASP.NET<br />
<a id="l0pm" title="http://msdn.microsoft.com/en-us/library/ms972961.aspx" href="http://msdn.microsoft.com/en-us/library/ms972961.aspx">http://msdn.microsoft.com/en-us/library/ms972961.aspx</a><br />
ASP.NET Validation in Depth<br />
<a id="p4_g" title="http://msdn.microsoft.com/en-us/library/aa479045.aspx" href="http://msdn.microsoft.com/en-us/library/aa479045.aspx">http://msdn.microsoft.com/en-us/library/aa479045.aspx</a><a id="ojb9" title="http://msdn.microsoft.com/en-us/library/aa479013.aspx" href="http://msdn.microsoft.com/en-us/library/aa479013.aspx"></a></p>
<p>My own post:<a href="http://wikiaspnet.wordpress.com/2008/08/22/validate-checkbox/" target="_blank"><br />
CheckBox Validation</a></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/notionstudio.wordpress.com/127/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/notionstudio.wordpress.com/127/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/notionstudio.wordpress.com/127/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/notionstudio.wordpress.com/127/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/notionstudio.wordpress.com/127/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/notionstudio.wordpress.com/127/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/notionstudio.wordpress.com/127/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/notionstudio.wordpress.com/127/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/notionstudio.wordpress.com/127/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/notionstudio.wordpress.com/127/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/notionstudio.wordpress.com/127/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/notionstudio.wordpress.com/127/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/notionstudio.wordpress.com/127/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/notionstudio.wordpress.com/127/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/notionstudio.wordpress.com/127/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/notionstudio.wordpress.com/127/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=notionstudio.wordpress.com&amp;blog=14839848&amp;post=127&amp;subd=notionstudio&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://notionstudio.wordpress.com/2008/08/22/aspnet-validation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/392dac9bbc3c8fea87e0533a51b59b37?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Slayter</media:title>
		</media:content>
	</item>
		<item>
		<title>CheckBox Validation</title>
		<link>http://notionstudio.wordpress.com/2008/08/22/validate-checkbox/</link>
		<comments>http://notionstudio.wordpress.com/2008/08/22/validate-checkbox/#comments</comments>
		<pubDate>Fri, 22 Aug 2008 18:55:21 +0000</pubDate>
		<dc:creator>Slayter</dc:creator>
				<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://wikiaspnet.wordpress.com/?p=123</guid>
		<description><![CDATA[ASP.NET provides all the wonderful validation controls and perform both client-side and server-side validation. However, to validate a CheckBox, only the Custom Validation Control can be used. Assume you have the following&#8230; &#60;span&#62;&#60;asp:CheckBox ID="MyCheckBox" runat="server" onClick="if (this.checked) CheckBoxChecked(); else CheckBoxUnchecked();" /&#62;Yes, your website is awesome! =) &#60;/span&#62; &#60;asp:CustomValidator ID="MyCheckBoxValidator" runat="server" ErrorMessage="Custom Validator" ClientValidationFunction="ClientValidateMyCheckBox" ValidationGroup="MyValidationGroup" OnServerValidate="MyCheckBoxValidator_ServerValidate"&#62;Required.&#60;/asp:CustomValidator&#62; [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=notionstudio.wordpress.com&amp;blog=14839848&amp;post=123&amp;subd=notionstudio&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>ASP.NET provides all the wonderful validation controls and perform both client-side and server-side validation. However, to validate a CheckBox, only the Custom Validation Control can be used. Assume you have the following&#8230;</p>
<div style="background-color:#cccccc;">
<pre>&lt;span&gt;&lt;asp:CheckBox ID="MyCheckBox" runat="server" onClick="if (this.checked) CheckBoxChecked(); else CheckBoxUnchecked();" /&gt;Yes, your website is awesome! =) &lt;/span&gt;
&lt;asp:CustomValidator ID="MyCheckBoxValidator" runat="server" ErrorMessage="Custom Validator" ClientValidationFunction="ClientValidateMyCheckBox"
    ValidationGroup="MyValidationGroup" OnServerValidate="MyCheckBoxValidator_ServerValidate"&gt;Required.&lt;/asp:CustomValidator&gt;</pre>
</div>
<p>Pure server-side validation will work, using the event handler <strong>MyCheckBoxValidator_ServerValidate</strong>. Here&#8217;s how it would look, and then start other methods with a check on <strong>Page.IsValid</strong></p>
<div style="background-color:#cccccc;">
<pre>protected void MyCheckBoxValidator_ServerValidate(object source, ServerValidateEventArgs args)
{
    args.IsValid = (MyCheckBox.Checked);
}</pre>
</div>
<p>On the other hand, it would be more efficient if client-side validation can also be done. The JavaScript function <strong>ClientValidateMyCheckBox</strong> is used for this purpose&#8230;</p>
<div style="background-color:#cccccc;">
<pre>&lt;script type="text/javascript"&gt;
function ClientValidateMyCheckBox(source, args)
{
    var cb = $get('&lt;%=MyCheckBox.ClientID%&gt;');
    args.IsValid = cb.checked;
}
&lt;/script&gt;</pre>
</div>
<p>This will trigger the client validation and if the CheckBox is unchecked, it will display the custom validator&#8217;s warning message. However, when you check the CheckBox now the validation warning message doesn&#8217;t disappear. This is because the client-side validation event is not triggerred during the client-side onClick event of the CheckBox. (Just a side-note, RequiredValidator and TextBox does not have this behavior. TextBox is validated as soon as something&#8217;s typed in.) To resolve this, a MS client-side JavaScript function needs to be hooked up with the onClick event of the CheckBox, <strong>Page_ClientValidate(&#8220;&lt;validation group name&gt;&#8221;)</strong> is the JS function to be used. Also note that for the &#8220;check and un-check&#8221; event of the CheckBox to work, we need to associate two functions to onClick, as shown below&#8230;</p>
<div style="background-color:#cccccc;">
<pre>function CheckBoxChecked()
{
    var cb = $get('&lt;%=MyCheckBox.ClientID%&gt;');
    cb.checked = true;
    <span style="color:#ff0000;"><strong>Page_ClientValidate("My_Validation_Group");</strong></span>
}
function CheckBoxUnchecked()
{
    var cb = $get('&lt;%=MyCheckBox.ClientID%&gt;');
    cb.checked = false;
    <strong><span style="color:#ff0000;">Page_ClientValidate("My_Validation_Group");</span></strong>
}</pre>
</div>
<p>Final NOTE, don&#8217;t leave the validation group name out because it will then validate everything else on your page. However, do NOT use the same group name as the one you assigned in the Custom Validator also, it just doesn&#8217;t work. I can see that it doesn&#8217;t work because the ControlToValidate property is not set, so there is no linkage.</p>
<p>So well yeah, this will do it&#8230; of course, change accordingly if that&#8217;s not the behavior you are looking for&#8230;</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/notionstudio.wordpress.com/123/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/notionstudio.wordpress.com/123/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/notionstudio.wordpress.com/123/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/notionstudio.wordpress.com/123/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/notionstudio.wordpress.com/123/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/notionstudio.wordpress.com/123/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/notionstudio.wordpress.com/123/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/notionstudio.wordpress.com/123/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/notionstudio.wordpress.com/123/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/notionstudio.wordpress.com/123/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/notionstudio.wordpress.com/123/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/notionstudio.wordpress.com/123/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/notionstudio.wordpress.com/123/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/notionstudio.wordpress.com/123/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/notionstudio.wordpress.com/123/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/notionstudio.wordpress.com/123/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=notionstudio.wordpress.com&amp;blog=14839848&amp;post=123&amp;subd=notionstudio&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://notionstudio.wordpress.com/2008/08/22/validate-checkbox/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/392dac9bbc3c8fea87e0533a51b59b37?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Slayter</media:title>
		</media:content>
	</item>
		<item>
		<title>CSS Friendly Adapters and Skins</title>
		<link>http://notionstudio.wordpress.com/2008/08/18/css-friendly-adapters-and-skins/</link>
		<comments>http://notionstudio.wordpress.com/2008/08/18/css-friendly-adapters-and-skins/#comments</comments>
		<pubDate>Mon, 18 Aug 2008 21:01:03 +0000</pubDate>
		<dc:creator>Slayter</dc:creator>
				<category><![CDATA[CSS]]></category>

		<guid isPermaLink="false">http://wikiaspnet.wordpress.com/?p=121</guid>
		<description><![CDATA[ASP.NET CSS Friendly Control Adapters http://www.asp.net/CSSAdapters/ http://www.codeplex.com/cssfriendly I guess this exists because Microsoft realizes that some of its rendered HTML code are not that easy to apply CSS to. So this adapter comes and stands in the way of the rendering process to generate different sets of HTML. It&#8217;s pretty cool because at the very [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=notionstudio.wordpress.com&amp;blog=14839848&amp;post=121&amp;subd=notionstudio&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>ASP.NET CSS Friendly Control Adapters<br /> <a id="e" title="http://www.asp.net/CSSAdapters/Menu.aspx" href="http://www.asp.net/CSSAdapters/Menu.aspx">http://www.asp.net/CSSAdapters/</a><br /> <a id="nvpo" title="http://www.codeplex.com/cssfriendly" href="http://www.codeplex.com/cssfriendly">http://www.codeplex.com/cssfriendly</a></p>
<p>I guess this exists because Microsoft realizes that some of its rendered HTML code are not that easy to apply CSS to. So this adapter comes and stands in the way of the rendering process to generate different sets of HTML. It&#8217;s pretty cool because at the very least it exposes the way to render customized HTML based on whatever requirements.</p>
<p>However, I don&#8217;t find it useful for all the controls it currently supports. On the contrary, some make it even harder to apply CSS to. With the help of Skin files, the look and feel of controls such GridView or DetailsView can be pretty well customized.</p>
<p>As of any other MS technologies, there are always more than one way of doing it. Whatever fits your need should be used&#8230;</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/notionstudio.wordpress.com/121/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/notionstudio.wordpress.com/121/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/notionstudio.wordpress.com/121/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/notionstudio.wordpress.com/121/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/notionstudio.wordpress.com/121/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/notionstudio.wordpress.com/121/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/notionstudio.wordpress.com/121/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/notionstudio.wordpress.com/121/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/notionstudio.wordpress.com/121/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/notionstudio.wordpress.com/121/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/notionstudio.wordpress.com/121/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/notionstudio.wordpress.com/121/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/notionstudio.wordpress.com/121/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/notionstudio.wordpress.com/121/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/notionstudio.wordpress.com/121/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/notionstudio.wordpress.com/121/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=notionstudio.wordpress.com&amp;blog=14839848&amp;post=121&amp;subd=notionstudio&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://notionstudio.wordpress.com/2008/08/18/css-friendly-adapters-and-skins/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/392dac9bbc3c8fea87e0533a51b59b37?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Slayter</media:title>
		</media:content>
	</item>
		<item>
		<title>Random Password Generation</title>
		<link>http://notionstudio.wordpress.com/2008/07/27/random-password-generation/</link>
		<comments>http://notionstudio.wordpress.com/2008/07/27/random-password-generation/#comments</comments>
		<pubDate>Sun, 27 Jul 2008 12:52:50 +0000</pubDate>
		<dc:creator>Slayter</dc:creator>
				<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://wikiaspnet.wordpress.com/?p=105</guid>
		<description><![CDATA[Pretty cool, can be used for many purposes, like generating the decryption and validation machine keys, etc&#8230; https://www.grc.com/passwords.htm<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=notionstudio.wordpress.com&amp;blog=14839848&amp;post=105&amp;subd=notionstudio&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Pretty cool, can be used for many purposes, like generating the decryption and validation machine keys, etc&#8230;</p>
<p><a href="https://www.grc.com/passwords.htm" target="_blank">https://www.grc.com/passwords.htm</a></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/notionstudio.wordpress.com/105/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/notionstudio.wordpress.com/105/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/notionstudio.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/notionstudio.wordpress.com/105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/notionstudio.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/notionstudio.wordpress.com/105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/notionstudio.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/notionstudio.wordpress.com/105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/notionstudio.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/notionstudio.wordpress.com/105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/notionstudio.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/notionstudio.wordpress.com/105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/notionstudio.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/notionstudio.wordpress.com/105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/notionstudio.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/notionstudio.wordpress.com/105/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=notionstudio.wordpress.com&amp;blog=14839848&amp;post=105&amp;subd=notionstudio&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://notionstudio.wordpress.com/2008/07/27/random-password-generation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/392dac9bbc3c8fea87e0533a51b59b37?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Slayter</media:title>
		</media:content>
	</item>
	</channel>
</rss>
