<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Didsbury Design Blog &#187; C-Sharp</title>
	<atom:link href="http://blog.didsburydesign.com/tag/c-sharp/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.didsburydesign.com</link>
	<description>Web Design and Development</description>
	<lastBuildDate>Fri, 04 Nov 2011 16:37:21 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Canonical URLs in your ASP.NET MVC2 / MVC3 Application</title>
		<link>http://blog.didsburydesign.com/2010/11/canonical-urls-in-your-asp-net-mvc2-mvc3-application/</link>
		<comments>http://blog.didsburydesign.com/2010/11/canonical-urls-in-your-asp-net-mvc2-mvc3-application/#comments</comments>
		<pubDate>Mon, 15 Nov 2010 12:43:11 +0000</pubDate>
		<dc:creator>Didsbury Design</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[MVC2]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C-Sharp]]></category>
		<category><![CDATA[canonical]]></category>
		<category><![CDATA[Filter attribute]]></category>
		<category><![CDATA[MVC3]]></category>
		<category><![CDATA[SEO]]></category>

		<guid isPermaLink="false">http://blog.didsburydesign.com/?p=276</guid>
		<description><![CDATA[What are canonical links used for
The Canonical link element was introduced in 2009 to help cleanup duplicate pages on search engines.
The html code is shown below and it basically informs search engines of the primary URL for that page. This means any alternative entry points to that page will not be picked up as duplicate [...]]]></description>
			<content:encoded><![CDATA[<p><strong>What are canonical links used for</strong><br />
The Canonical link element was introduced in 2009 to help cleanup duplicate pages on search engines.<br />
The html code is shown below and it basically informs search engines of the primary URL for that page. This means any alternative entry points to that page will not be picked up as duplicate content. This HTML must be specified in the HEAD section of the document.</p>

<div class="wp_syntax"><div class="code"><pre class="xhtml" style="font-family:monospace;">&lt;link rel=&quot;canonical&quot; href=&quot;http://example.com/page.html&quot;/&gt;</pre></div></div>

<p>The search engines have also posted about this on a Google <a href="http://googlewebmastercentral.blogspot.com/2009/02/specify-your-canonical.html">blog post</a> or <a href="http://google.com/support/webmasters/bin/answer.py?answer=139394">help center documentation</a> from Google, <a href="http://ysearchblog.com/2009/02/12/fighting-duplication-adding-more-arrows-to-your-quiver/">Yahoo’s blog post</a>, or <a href="http://blogs.msdn.com/webmaster/archive/2009/02/12/partnering-to-help-solve-duplicate-content-issues.aspx">Microsoft’s blog post</a>.</p>
<p><strong>How to easily use canonical links in MVC2 using Action Filters and Master Pages</strong></p>
<p>Add this to the master page in the head section as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">    <span style="color: #339933;">&lt;%=</span>ViewData<span style="color: #009900;">&#91;</span><span style="color: #ff0000;">&quot;CanonicalURL&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">%&gt;</span>
    <span style="color: #339933;">&lt;!--</span>Your other head info here<span style="color: #339933;">--&gt;</span></pre></div></div>

<p>Create a Filter Attribute (CanonicalURL.cs):</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">public class CanonicalURL <span style="color: #339933;">:</span> ActionFilterAttribute
<span style="color: #009900;">&#123;</span>
    public <span style="color: #993333;">string</span> Url <span style="color: #009900;">&#123;</span> get<span style="color: #339933;">;</span> private set<span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
&nbsp;
    public CanonicalURL<span style="color: #009900;">&#40;</span><span style="color: #993333;">string</span> url<span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
       Url <span style="color: #339933;">=</span> url<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    public override <span style="color: #993333;">void</span> OnResultExecuting<span style="color: #009900;">&#40;</span>ResultExecutingContext filterContext<span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #993333;">string</span> fullyQualifiedUrl <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;http://www.example.com&quot;</span> <span style="color: #339933;">+</span> this.<span style="color: #202020;">Url</span><span style="color: #339933;">;</span>
        filterContext.<span style="color: #202020;">Controller</span>.<span style="color: #202020;">ViewData</span><span style="color: #009900;">&#91;</span><span style="color: #ff0000;">&quot;CanonicalUrl&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> @<span style="color: #ff0000;">&quot;&lt;link rel='canonical' href='&quot;</span> <span style="color: #339933;">+</span> fullyQualifiedUrl <span style="color: #339933;">+</span> <span style="color: #ff0000;">&quot;' /&gt;&quot;</span><span style="color: #339933;">;</span>
        base.<span style="color: #202020;">OnResultExecuting</span><span style="color: #009900;">&#40;</span>filterContext<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Call this from your actions:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #009900;">&#91;</span>CanonicalURL<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Contact-Us&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span>
public ActionResult Index<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
 <span style="color: #009900;">&#123;</span>
      ContactFormViewModel contact <span style="color: #339933;">=</span> new ContactFormViewModel<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
      <span style="color: #b1b100;">return</span> View<span style="color: #009900;">&#40;</span>contact<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>For some other interesting articles on Search Engine Related posts check out <a href="http://www.mattcutts.com/blog/canonical-link-tag/" rel="nofollow">Matt Cutts blog</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.didsburydesign.com/2010/11/canonical-urls-in-your-asp-net-mvc2-mvc3-application/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>ASP.NET MVC 3 Release Candidate is now available</title>
		<link>http://blog.didsburydesign.com/2010/11/asp-net-mvc-3-release-candidate-is-now-available/</link>
		<comments>http://blog.didsburydesign.com/2010/11/asp-net-mvc-3-release-candidate-is-now-available/#comments</comments>
		<pubDate>Wed, 10 Nov 2010 11:23:06 +0000</pubDate>
		<dc:creator>Didsbury Design</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C-Sharp]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[mvc 3.0 RC]]></category>

		<guid isPermaLink="false">http://blog.didsburydesign.com/?p=266</guid>
		<description><![CDATA[ASP.NET MVC 3 Release Candidate is now available for download. Phil Haack has written an article about it and also mentions the intentions for MVC 4.
Phil Haack&#8217;s blog post: ASP.NET MVC 3 Release Candidate

Direct download: MVC 3 RC Download
]]></description>
			<content:encoded><![CDATA[<p>ASP.NET MVC 3 Release Candidate is now available for download. Phil Haack has written an article about it and also mentions the intentions for MVC 4.</p>
<p>Phil Haack&#8217;s blog post: <a href="http://haacked.com/archive/2010/11/09/asp-net-mvc-3-release-candidate.aspx?utm_source=feedburner&#038;utm_medium=feed&#038;utm_campaign=Feed%3A+haacked+%28you%27ve+been+HAACKED%29">ASP.NET MVC 3 Release Candidate<br />
</a></p>
<p>Direct download: <a href="http://go.microsoft.com/fwlink/?LinkID=191797">MVC 3 RC Download</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.didsburydesign.com/2010/11/asp-net-mvc-3-release-candidate-is-now-available/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to: Create and Delete a cookie in ASP.NET C#</title>
		<link>http://blog.didsburydesign.com/2010/04/how-to-create-and-delete-a-cookie-in-asp-net-c/</link>
		<comments>http://blog.didsburydesign.com/2010/04/how-to-create-and-delete-a-cookie-in-asp-net-c/#comments</comments>
		<pubDate>Thu, 29 Apr 2010 12:27:55 +0000</pubDate>
		<dc:creator>Didsbury Design</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C-Sharp]]></category>
		<category><![CDATA[cookie]]></category>
		<category><![CDATA[cookies]]></category>
		<category><![CDATA[how to]]></category>
		<category><![CDATA[session]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://blog.zero7web.com/?p=232</guid>
		<description><![CDATA[I thought I would do a quick post about Creating and more importantly Deleting cookies in ASP.NET as it&#8217;s not quite as obvious as it may seem with the misleading .Remove() method which doesnt do as you would expect.
I hope this helps someone get started with cookies if your just getting started with the .NET [...]]]></description>
			<content:encoded><![CDATA[<p>I thought I would do a quick post about Creating and more importantly Deleting cookies in ASP.NET as it&#8217;s not quite as obvious as it may seem with the misleading .Remove() method which doesnt do as you would expect.</p>
<p>I hope this helps someone get started with cookies if your just getting started with the .NET framework.<br />
</p>
<h2>Creating a cookie</h2>
<p>
This is a basic example of how to create a cookie in ASP.NET C#<br />
 </p>
<pre>//Create a new cookie, passing the name into the constructor
HttpCookie cookie = new HttpCookie("MyCookie");

//Set the cookies value
cookie.Value = "CookieValue";

//Set the cookie to expire in 1 day
cookie.Expires = DateTime.Now.AddDays(1);

//Add the cookie
Response.Cookies.Add(cookie);</pre>
<h2>Deleting a cookie</h2>
<p>
When deleting a cookie all you need to do is amend the HttpCookie object so it has an expiry date in the past, then re-save the cookie to push the new value to the client.<br />
</p>
<pre>// Clear cookie Info
            if(Request.Cookies["MyCookie"]!=null){

                HttpCookie cookie = Request.Cookies["MyCookie"];
                cookie.Expires = DateTime.Now.AddDays(-1);

                Response.Cookies.Add(cookie);
            }</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.didsburydesign.com/2010/04/how-to-create-and-delete-a-cookie-in-asp-net-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to: Allow hyphens in URL&#8217;s using ASP.NET MVC 2</title>
		<link>http://blog.didsburydesign.com/2010/02/how-to-allow-hyphens-in-urls-using-asp-net-mvc-2/</link>
		<comments>http://blog.didsburydesign.com/2010/02/how-to-allow-hyphens-in-urls-using-asp-net-mvc-2/#comments</comments>
		<pubDate>Sat, 06 Feb 2010 14:28:03 +0000</pubDate>
		<dc:creator>Didsbury Design</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C-Sharp]]></category>
		<category><![CDATA[Hyphens]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[MVC 2.0]]></category>
		<category><![CDATA[URL Routing]]></category>

		<guid isPermaLink="false">http://blog.zero7web.com/?p=200</guid>
		<description><![CDATA[If you wan&#8217;t to allow hyphens in your URL&#8217;s you will need to change the way the routing works in your Global.asax file.
First create a new class which extends the MvcRouteHandler and place this in the Global.asax file after the main MvcApplication class.
C#:

public class HyphenatedRouteHandler : MvcRouteHandler&#123;
	protected override IHttpHandler  GetHttpHandler&#40;RequestContext requestContext&#41;
	&#123;
		requestContext.RouteData.Values&#91;&#34;controller&#34;&#93; = requestContext.RouteData.Values&#91;&#34;controller&#34;&#93;.ToString&#40;&#41;.Replace&#40;&#34;-&#34;, &#34;_&#34;&#41;;
		requestContext.RouteData.Values&#91;&#34;action&#34;&#93; [...]]]></description>
			<content:encoded><![CDATA[<p>If you wan&#8217;t to allow hyphens in your URL&#8217;s you will need to change the way the routing works in your Global.asax file.</p>
<p>First create a new class which extends the <strong>MvcRouteHandler</strong> and place this in the <strong>Global.asax</strong> file after the main <strong>MvcApplication</strong> class.</p>
<p>C#:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">public class HyphenatedRouteHandler <span style="color: #339933;">:</span> MvcRouteHandler<span style="color: #009900;">&#123;</span>
	protected override IHttpHandler  GetHttpHandler<span style="color: #009900;">&#40;</span>RequestContext requestContext<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		requestContext.<span style="color: #202020;">RouteData</span>.<span style="color: #202020;">Values</span><span style="color: #009900;">&#91;</span><span style="color: #ff0000;">&quot;controller&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> requestContext.<span style="color: #202020;">RouteData</span>.<span style="color: #202020;">Values</span><span style="color: #009900;">&#91;</span><span style="color: #ff0000;">&quot;controller&quot;</span><span style="color: #009900;">&#93;</span>.<span style="color: #202020;">ToString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #202020;">Replace</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;-&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;_&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		requestContext.<span style="color: #202020;">RouteData</span>.<span style="color: #202020;">Values</span><span style="color: #009900;">&#91;</span><span style="color: #ff0000;">&quot;action&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> requestContext.<span style="color: #202020;">RouteData</span>.<span style="color: #202020;">Values</span><span style="color: #009900;">&#91;</span><span style="color: #ff0000;">&quot;action&quot;</span><span style="color: #009900;">&#93;</span>.<span style="color: #202020;">ToString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #202020;">Replace</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;-&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;_&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">return</span> base.<span style="color: #202020;">GetHttpHandler</span><span style="color: #009900;">&#40;</span>requestContext<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>VB:</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:monospace;"><span style="color: #000080;">Public</span> Class HyphenatedRouteHandler
    Inherits MvcRouteHandler
&nbsp;
    Protected Overrides <span style="color: #000080;">Function</span> GetHttpHandler(<span style="color: #000080;">ByVal</span> requestContext <span style="color: #000080;">As</span> System.Web.Routing.RequestContext) <span style="color: #000080;">As</span> System.Web.IHttpHandler
        requestContext.RouteData.Values(&quot;controller&quot;) = requestContext.RouteData.Values(&quot;controller&quot;).ToString.Replace(&quot;-&quot;, &quot;_&quot;)
        requestContext.RouteData.Values(&quot;action&quot;) = requestContext.RouteData.Values(&quot;action&quot;).ToString.Replace(&quot;-&quot;, &quot;_&quot;)
        Return MyBase.GetHttpHandler(requestContext)
    <span style="color: #000080;">End</span> <span style="color: #000080;">Function</span>
&nbsp;
<span style="color: #000080;">End</span> Class</pre></div></div>

<p>Then you need to replace the <strong>routes.MapRoute</strong> with an equivalent <strong>routes.Add</strong> specifying the new handler as the MapRoute does not allow you to specify a custom route handler.</p>
<p>C#:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">routes.<span style="color: #202020;">Add</span><span style="color: #009900;">&#40;</span>
	new Route<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;{controller}/{action}/{id}&quot;</span><span style="color: #339933;">,</span> 
		new RouteValueDictionary<span style="color: #009900;">&#40;</span>
			new <span style="color: #009900;">&#123;</span> controller <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;Default&quot;</span><span style="color: #339933;">,</span> action <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;Index&quot;</span><span style="color: #339933;">,</span> id <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
			new HyphenatedRouteHandler<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>VB:</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:monospace;">routes.Add(<span style="color: #000080;">New</span> Route(&quot;{controller}/{action}/{id}&quot;, 
	<span style="color: #000080;">New</span> RouteValueDictionary(<span style="color: #000080;">New</span> <span style="color: #000080;">With</span> {.controller = &quot;Home&quot;, .action = &quot;Index&quot;, .id = &quot;&quot;}), 
		<span style="color: #000080;">New</span> HyphenatedRouteHandler()))</pre></div></div>

<p>I hope this is useful, any questions feel free to get in touch.</p>
<p>Would like to say thanks to John from <a href="http://stackoverflow.com/questions/2070890/asp-net-mvc-support-for-urls-with-hyphens">here</a> for answering the original question on <a href="http://stackoverflow.com">Stackoverflow</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.didsburydesign.com/2010/02/how-to-allow-hyphens-in-urls-using-asp-net-mvc-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

