<?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>Avivo Tech Blog &#187; ASP.NET MVC</title>
	<atom:link href="http://tech.avivo.si/category/aspnet-mvc/feed/" rel="self" type="application/rss+xml" />
	<link>http://tech.avivo.si</link>
	<description>Solving problems</description>
	<lastBuildDate>Tue, 24 Jan 2012 14:46:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
		<item>
		<title>The easiest way to generate a QR Code for software developers</title>
		<link>http://tech.avivo.si/2012/01/the-easiest-way-to-generate-a-qr-code-for-programmers/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=the-easiest-way-to-generate-a-qr-code-for-programmers</link>
		<comments>http://tech.avivo.si/2012/01/the-easiest-way-to-generate-a-qr-code-for-programmers/#comments</comments>
		<pubDate>Tue, 24 Jan 2012 14:46:11 +0000</pubDate>
		<dc:creator>developer</dc:creator>
				<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[HTML, Javascript and CSS]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[Silverlight/WPF]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[Web Services]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[example]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[qr code generators]]></category>
		<category><![CDATA[sample]]></category>
		<category><![CDATA[simple]]></category>
		<category><![CDATA[web service]]></category>

		<guid isPermaLink="false">http://tech.avivo.si/?p=1445</guid>
		<description><![CDATA[So you want to simply generate a QR Code image without diving into the technical specifics? This blog post contains a few simple examples. Just copy-paste where you need it. Idea is to build a URL, make an HTTP request and download the QR Code image. Result is the following image: HTTP Request URL looks [...]]]></description>
			<content:encoded><![CDATA[<p>So you want to simply generate a QR Code image without diving into the technical specifics? This blog post contains a few simple examples. Just copy-paste where you need it.</p>
<p>Idea is to build a URL, make an HTTP request and download the QR Code image. Result is the following image:</p>
<pre><img src="http://www.esponce.com/api/v3/generate?content=your%20content%20goes%20here&#038;format=png" alt="your content goes here" /></pre>
<h2>HTTP Request</h2>
<p>URL looks like<strong> http://www.esponce.com/api/v3/generate?content={content}&amp;format={format}</strong> where <strong>{content}</strong> is URL encoded content to be embedded in QR and <strong>{format}</strong> is output image format. Available formats are <strong>png, jpg, bmp, tif, xaml, svg, eps, txt, html, zip</strong> (containing all listed formats)</p>
<p>List of other parameters like color and size can be found <a href="http://www.esponce.com/help/api-v3/generate#parameters">here</a>.</p>
<h2>C# Sample</h2>
<p>This code can be used in <strong>.NET 2.0</strong> including ASP.NET and WPF or <strong>Silverlight</strong> for web or <strong>WP7</strong></p>
<pre class="brush: csharp; title: ; notranslate">
using System;
using System.IO;
using System.Web;
using System.Net;

public class Program
{
  public static void Main(string[] args)
  {
    //Generate a QR Code and save it to file &quot;sample.png&quot;
    Generate(&quot;your content goes here&quot;, &quot;png&quot;, &quot;sample.png&quot;);
  }

  public static void Generate(string content, string format, string path)
  {
    string encoded = HttpUtility.UrlEncode(content);
    Uri uri = new Uri(&quot;http://www.esponce.com/api/v3/generate?content=&quot; + encoded + &quot;&amp;format=&quot; + format);
    WebClient client = new WebClient();
    client.DownloadFile(uri, path);
  }
}
</pre>
<h2>Java Sample</h2>
<p>This code can be used in a classic <strong>Java</strong> application or web <strong>applet</strong> or <strong>Android</strong> application</p>
<pre class="brush: java; title: ; notranslate">
import java.io.*;
import java.net.*;

public class qrcode
{
  public static void main(String args[])
  {
    //Generate a QR Code image and save it to file &quot;sample.png&quot;
    generate(&quot;your content goes here&quot;, &quot;png&quot;, &quot;sample.png&quot;);
  }

  public static void generate(String content, String format, String path)
  {
    try
    {
      String encoded = URLEncoder.encode(content, &quot;UTF-8&quot;);
      String url = &quot;http://www.esponce.com/api/v3/generate?content=&quot; + encoded + &quot;&amp;format=&quot; + format;
      BufferedInputStream ins = new BufferedInputStream(new URL(url).openStream());
      FileOutputStream fos = new FileOutputStream(path);
      BufferedOutputStream bos = new BufferedOutputStream(fos, 1024);

      int size = 0;
      byte data[] = new byte[1024];
      while ((size = ins.read(data, 0, 1024)) &amp;gt; 0)
      {
        bos.write(data, 0, size);
      }

      bos.close();
      fos.close();
      ins.close();
    }
    catch (Exception e)
    {
    }
  }
}
</pre>
<h2>Python Sample</h2>
<p>Using Python 2.7</p>
<pre class="brush: python; title: ; notranslate">
#!/usr/bin/env python
# -*- coding: UTF-8 -*-

import urllib
import httplib

def generate(content, format = &quot;png&quot;):
    query = urllib.urlencode({ &quot;content&quot;: content, &quot;format&quot;: format })
    con = httplib.HTTPConnection(&quot;www.esponce.com&quot;)
    con.request(&quot;GET&quot;, &quot;/api/v3/generate?&quot; + query)
    response = con.getresponse()
    image = response.read()
    con.close()
    return image

image = generate(&quot;your content goes here&quot;)
file = open(&quot;sample.png&quot;, &quot;wb&quot;)
file.write(image)
file.close()
</pre>
<h2>JavaScript Sample</h2>
<p>JavaScript in combination with HTML</p>
<pre class="brush: jscript; title: ; notranslate">
&lt;img id=&quot;qrcode&quot; src=&quot;&quot; alt=&quot;QR Code&quot; /&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
    function generate(content)
    {
        var url = &quot;http://www.esponce.com/api/v3/generate?content=&quot; + encodeURI(content) + &quot;&amp;format=png&quot;;
        var img = document.getElementById(&quot;qrcode&quot;);
        img.src = url;
    }
    generate(&quot;your content goes here&quot;);
&lt;/script&gt;
</pre>
<h2>PHP Sample</h2>
<pre class="brush: php; title: ; notranslate">
&lt;img src=&quot;&lt;?php echo generate(&quot;your content goes here&quot;); ?&gt;&quot; alt=&quot;QR Code&quot; /&gt;

&lt;?php
function generate($content, $format = &quot;png&quot;)
{
    $encoded = urlencode($content);
    $url = &quot;http://www.esponce.com/api/v3/generate?content=$encoded&amp;format=$format&quot;;
    return $url;
}
?&gt;
</pre>
<h2>There is more</h2>
<p>Download all samples with <em>make</em> script <a href="http://tech.avivo.si/wp-content/uploads/2012/01/generate-qr-code-samples-src.zip">here</a>.</p>
<p>Other QR Code related methods like decoding (reverse process of generating) and tracking scans can be found at <a href="http://www.esponce.com/help">esponce.com</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://tech.avivo.si/2012/01/the-easiest-way-to-generate-a-qr-code-for-programmers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Set IIS binding manually (add and remove IIS binding)</title>
		<link>http://tech.avivo.si/2011/12/set-iis-binding-manually-add-and-remove-iis-binding/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=set-iis-binding-manually-add-and-remove-iis-binding</link>
		<comments>http://tech.avivo.si/2011/12/set-iis-binding-manually-add-and-remove-iis-binding/#comments</comments>
		<pubDate>Fri, 09 Dec 2011 14:22:57 +0000</pubDate>
		<dc:creator>Avivo</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[Silverlight/WPF]]></category>
		<category><![CDATA[adding binding to iis from command line]]></category>
		<category><![CDATA[bindings]]></category>
		<category><![CDATA[change iis bindings from asp.net mvc website]]></category>
		<category><![CDATA[iis 7]]></category>
		<category><![CDATA[iis bindings]]></category>

		<guid isPermaLink="false">http://tech.avivo.si/?p=1422</guid>
		<description><![CDATA[We had an issue that we need to add or remove IIS 7 or IIS 7.5 additional bindings on one web application and we wanted to do this from one of our ASP.NET MVC applications. It is possible so you need to use IIS system program appcmd.exe (you can find it in C:\Windows\System32\inetsrv\ (we suggest [...]]]></description>
			<content:encoded><![CDATA[<p>We had an issue that we need to add or remove IIS 7 or IIS 7.5 <strong>additional bindings</strong> on one web application and we wanted to do this from one of our ASP.NET MVC applications.</p>
<p>It is possible so you need to use IIS system program <strong>appcmd.exe</strong> (you can find it in <strong>C:\Windows\System32\inetsrv\</strong> (we suggest you to put this into your PATH variable)</p>
<h3><strong>Adding additional bindings</strong></h3>
<p>You want to add <strong>your</strong><strong>-subdomain.your-domain.com</strong> binding to your IIS 7 app named <strong>your-domain.com</strong></p>
<p><span style="color: #ff0000;">C:\Windows\System32\inetsrv\appcmd set site /site.name: <strong>your-domain.com</strong> /+bindings.[protocol='http',bindingInformation='*:80:<strong>your-subdomain.your-domain.com</strong>']</span></p>
<h3><strong>Removing existing bindings</strong></h3>
<p>You want to <strong>remove </strong><strong>your</strong><strong>-subdomain.your-domain.com</strong> binding from your IIS 7 app named <strong>your-domain.com </strong>(please notice <strong>- sign</strong> in front of <strong>bindings </strong>word)<strong><br />
</strong></p>
<p><span style="color: #ff0000;">C:\Windows\System32\inetsrv\appcmd set site /site.name: <strong>your-domain.com</strong> /-bindings.[protocol='http',bindingInformation='*:80:<strong>your-subdomain.your-domain.com</strong>']</span></p>
<p>And that&#8217;s it but if you want to run it from ASP.NET you could try to use Process and ProcessInfo classes to run DOS command but there are some permissions problems (we didn&#8217;t investigated much).</p>
<p>Other (alternative way that we tried is directly from the code)<br />
You will need to reference this DLL: <strong>c:\Windows\System32\inetsrv\Microsoft.Web.Administration.dll </strong></p>
<pre>using (ServerManager serverManager = new ServerManager())
{
  if (serverManager.Sites == null)
    throw new SimpleException("There are no IIS applications!");

  var esponceApp = serverManager.Sites.FirstOrDefault(
x =&gt; x.Name == Settings.IISAppName);
  if (esponceApp != null)
  {
    BindingCollection bindingCollection = esponceApp.Bindings;
    Binding binding = bindingCollection.CreateElement("binding");
    binding["protocol"] = "http";
    binding["bindingInformation"] =
string.Format(@"{0}:{1}:{2}", "*", "80", this.DomainName);

    //Remove this binding if already exists.
    int oldBindingIndex = -1;
    int bindingIndex = -1;
    foreach (Binding currentBinding in esponceApp.Bindings)
    {
      if (currentBinding.BindingInformation ==
binding["bindingInformation"].ToString())
      {
        bindingIndex = esponceApp.Bindings.IndexOf(currentBinding);
      }
      if (!string.IsNullOrEmpty(oldDomainName) &amp;&amp;
      currentBinding.BindingInformation ==
string.Format(@"{0}:{1}:{2}", "*", "80", oldDomainName))
      {
        oldBindingIndex = esponceApp.Bindings.IndexOf(currentBinding);
      }
    }
    if (bindingIndex != -1)
    {
      esponceApp.Bindings.RemoveAt(bindingIndex);
    }
    if (oldBindingIndex != bindingIndex &amp;&amp; oldBindingIndex != -1)
    {
      esponceApp.Bindings.RemoveAt(oldBindingIndex);
    }

    //Add this bindings
    bindingCollection.Add(binding);
    serverManager.CommitChanges();
  }
}
}
catch
{
throw new SimpleException("Could not add binding into IIS application!");
}</pre>
<p>Important!<br />
Set identity of your app&#8217;s <strong>Application Domain</strong> from <strong>Advanced Settings &gt; Process Model &gt; Identity &gt; Change &#8220;ApplicationPoolIdentity&#8221; to &#8220;Local System&#8221;</strong></p>
<p>Investigate also security implications if you are not running this in Intranet&#8230;.</p>
]]></content:encoded>
			<wfw:commentRss>http://tech.avivo.si/2011/12/set-iis-binding-manually-add-and-remove-iis-binding/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>So, you can not delete Cookie? Huh, something about headers or headache&#8230;</title>
		<link>http://tech.avivo.si/2011/07/so-you-can-not-delete-cookie-huh-something-about-headers-or-headache/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=so-you-can-not-delete-cookie-huh-something-about-headers-or-headache</link>
		<comments>http://tech.avivo.si/2011/07/so-you-can-not-delete-cookie-huh-something-about-headers-or-headache/#comments</comments>
		<pubDate>Thu, 07 Jul 2011 12:18:55 +0000</pubDate>
		<dc:creator>Avivo</dc:creator>
				<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA["Server cannot modify cookies after HTTP headers have been sent"]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[can not delete cookie]]></category>
		<category><![CDATA[charp]]></category>
		<category><![CDATA[cookie]]></category>
		<category><![CDATA[delete cookie]]></category>
		<category><![CDATA[headers]]></category>
		<category><![CDATA[response]]></category>

		<guid isPermaLink="false">http://tech.avivo.si/?p=1337</guid>
		<description><![CDATA[We wanted to delete cookie setting its expired date property to something in the past like this: HttpCookie cookie = new HttpCookie(this.Name); cookie.Expires = DateTime.UtcNow.AddMonths(-1); HttpContext.Current.Response.Cookies.Add(cookie); But we got an error: Server cannot modify cookies after HTTP headers have been sent. After searching and searching if we have somewhere Response.Write in or ASP.NET MVC code [...]]]></description>
			<content:encoded><![CDATA[<p>We wanted to delete cookie setting its expired date property to something in the past like this:</p>
<pre class="csharp">
HttpCookie cookie = new HttpCookie(this.Name);
cookie.Expires = DateTime.UtcNow.AddMonths(-1);
HttpContext.Current.Response.Cookies.Add(cookie);
</pre>
<div style="margin-top:30px;">But we got an error: </div>
<p><b>Server cannot modify cookies after HTTP headers have been sent.</b></p>
<p>After searching and searching if we have somewhere <b>Response.Write</b> in or ASP.NET MVC code we found out that we don&#8217;t have such things.<br />
Suddenly, we found out that we played with <b>Session</b> object (trying to clear it) before deleting <b>Cookie</b> and that was it. Reordering these operations solved our problem.</p>
<div style="margin-top:30px;"><b>Conclusion</b><br/>Session object also use cookies, we forgot.</div>
<h2 style="margin-top:30px; color:red;">Update on this case</h2>
<div style="margin-top:20px; color:red;">
This &#8220;solution&#8221; didn&#8217;t helped&#8230; Everything is so simple and was done with <a href="http://www.electrictoolbox.com/jquery-cookies/" target="_blank">JQuery cookie plugin</a>. One line of code from Javascript!</div>
]]></content:encoded>
			<wfw:commentRss>http://tech.avivo.si/2011/07/so-you-can-not-delete-cookie-huh-something-about-headers-or-headache/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>QR Codes API &#8211; automatically generated for given content</title>
		<link>http://tech.avivo.si/2011/05/qr-codes-api-automatically-generated-for-given-content/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=qr-codes-api-automatically-generated-for-given-content</link>
		<comments>http://tech.avivo.si/2011/05/qr-codes-api-automatically-generated-for-given-content/#comments</comments>
		<pubDate>Mon, 16 May 2011 18:31:05 +0000</pubDate>
		<dc:creator>Avivo</dc:creator>
				<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[HTML, Javascript and CSS]]></category>
		<category><![CDATA[Programming Techniques]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[Social networks]]></category>
		<category><![CDATA[Web Services]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[barcode]]></category>
		<category><![CDATA[branding]]></category>
		<category><![CDATA[facebook]]></category>
		<category><![CDATA[mobile]]></category>
		<category><![CDATA[qr code generators]]></category>
		<category><![CDATA[qr codes]]></category>
		<category><![CDATA[qrcode]]></category>
		<category><![CDATA[scanner]]></category>
		<category><![CDATA[smart phones]]></category>
		<category><![CDATA[social networks]]></category>
		<category><![CDATA[tracking]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://tech.avivo.si/?p=1318</guid>
		<description><![CDATA[There are a lot of  QR Code generators on a web and there is also listed our generator &#8211; available at http://qrcode.good-survey.com It already went over simple generator functionality and new features are adding. Basically, beside QR Code generation, we are offering as addition: Tracking of generated QR Codes &#8211; for marketing managers ti know [...]]]></description>
			<content:encoded><![CDATA[<p>There are a lot of  <a title="QR Code generators" href="http://2d-code.co.uk/qr-code-generators/" target="_blank">QR Code generators</a> on a web and there is also listed our generator &#8211; available at <a title="Good Survey QR Code Generator and Tracking" href="http://qrcode.good-survey.com" target="_blank">http://qrcode.good-survey.com</a></p>
<p>It already went over simple generator functionality and new features are adding.</p>
<div id="attachment_1325" class="wp-caption alignnone" style="width: 710px"><img class="size-large wp-image-1325" title="QR Codes Generator and API" src="http://tech.avivo.si/wp-content/uploads/2011/05/qr-codes-generator-and-api-700x475.jpg" alt="QR Codes Generator and API" width="700" height="475" /><p class="wp-caption-text">QR Codes Generator and API</p></div>
<p>Basically, beside QR Code generation, we are offering as addition:</p>
<ul>
<li>Tracking of generated QR Codes &#8211; for marketing managers ti know which locations work best (i.e. posters with printed QR Code)</li>
<li>Dynamic QR Codes &#8211; if some QR Code is already printed you can make it point to completely different URL without changing the printed code</li>
<li>Adding your logo inside QR Code (with readability testing) &#8211; branding feature</li>
<li>All types of content are supported (hyperlinks, custom text, vCard, Bizcard, Mecard,  vCalendar, social networks &#8211; Twitter, Facebook, YouTube, Geo locations and maps, SMS messages, phones,&#8230;)</li>
<li>Strong use of API &#8211; automating generation process and possibility to use from your application/website &#8211; this is what we will talk about a little bit more in this article&#8230;</li>
</ul>
<p>Using API is not complicated at all, <a title="QR Codes API" href="http://qrcode.good-survey.com/help" target="_blank">we wrote a tutorial</a> which is easy to understand.</p>
<p>Here is an example how you can have instantly QR Code image on your website:</p>
<p>This are direct links:</p>
<ul>
<li><a href="http://qrcode.good-survey.com/api/v2/generate?content=Hello%20World&amp;format=png&amp;padding=2&amp;size=10&amp;em=byte&amp;ec=m" target="_blank">Hello World custom text</a></li>
<li><a href="http://qrcode.good-survey.com/api/v2/generate?content=http%3a%2f%2fmaps.google.com%2fmaps%3ff%3dq%26q%3d46.043286%2c14.492791300000022%26q%3d30%2bTeslova%2bUlica%252c%2bLjubljana%2b1000%252c%2bSlovenia&amp;format=png&amp;padding=2&amp;size=10&amp;em=byte&amp;ec=m" target="_blank">Google Maps location of company&#8217;s office</a></li>
<li><a href="http://qrcode.good-survey.com/api/v2/generate?content=http%3a%2f%2fqrcode.good-survey.com&amp;format=png&amp;padding=2&amp;size=10&amp;em=byte&amp;ec=m" target="_blank">QR Code generator URL</a></li>
</ul>
<p>This how it could look like inside your website (just put this hyperlink inside your IMG tag)</p>
<pre lang="csharp">&lt;img src="http://qrcode.good-survey.com/api/v2/generate?content=
http%3a%2f%2fmaps.google.com%2fmaps%3ff%3dq%26q%3d46.043286%2c14.492791300000022%
26q%3d30%2bTeslova%2bUlica%252c%2bLjubljana%2b1000%252c%2bSlovenia&amp;
format=png&amp;padding=2&amp;size=10&amp;em=byte&amp;ec=m" alt="Avivo location" /&gt;</pre>
<div style="margin-top:20px;">
Try it also by yourself &#8211; just download <a title="QR Codes API demo application" href="http://qrcodeapi.codeplex.com/" target="_blank">DEMO API application</a> from CodePlex and you can play with supported API features.</div>
]]></content:encoded>
			<wfw:commentRss>http://tech.avivo.si/2011/05/qr-codes-api-automatically-generated-for-given-content/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Create random web hex color in C# / ASP.NET MVC</title>
		<link>http://tech.avivo.si/2011/04/create-random-web-hex-color-in-c-asp-net-mvc/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=create-random-web-hex-color-in-c-asp-net-mvc</link>
		<comments>http://tech.avivo.si/2011/04/create-random-web-hex-color-in-c-asp-net-mvc/#comments</comments>
		<pubDate>Fri, 22 Apr 2011 22:46:16 +0000</pubDate>
		<dc:creator>Avivo</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[Programming Techniques]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[color]]></category>
		<category><![CDATA[colour]]></category>
		<category><![CDATA[hash color]]></category>
		<category><![CDATA[random color]]></category>
		<category><![CDATA[web color]]></category>

		<guid isPermaLink="false">http://tech.avivo.si/?p=1305</guid>
		<description><![CDATA[Random random = new Random(); int red = random.Next(0, 255); int green = random.Next(0, 255); int blue = random.Next(0, 255); string hexColour = String.Format("#{0:X2}{1:X2}{2:X2}", red, green, blue);]]></description>
			<content:encoded><![CDATA[<pre class=csharp>
Random random = new Random();
int red = random.Next(0, 255);
int green = random.Next(0, 255);
int blue = random.Next(0, 255);
string hexColour = String.Format("#{0:X2}{1:X2}{2:X2}", red, green, blue);
</pre>
]]></content:encoded>
			<wfw:commentRss>http://tech.avivo.si/2011/04/create-random-web-hex-color-in-c-asp-net-mvc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to copy validation message from one element to another in ASP.NET MVC 2?</title>
		<link>http://tech.avivo.si/2011/04/how-to-copy-validation-message-from-one-element-to-another-in-asp-net-mvc-2/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=how-to-copy-validation-message-from-one-element-to-another-in-asp-net-mvc-2</link>
		<comments>http://tech.avivo.si/2011/04/how-to-copy-validation-message-from-one-element-to-another-in-asp-net-mvc-2/#comments</comments>
		<pubDate>Mon, 04 Apr 2011 14:47:58 +0000</pubDate>
		<dc:creator>Avivo</dc:creator>
				<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[Programming Techniques]]></category>
		<category><![CDATA[copy validation message]]></category>
		<category><![CDATA[microsoft]]></category>
		<category><![CDATA[mvc 2]]></category>
		<category><![CDATA[validation in mvc 2]]></category>

		<guid isPermaLink="false">http://tech.avivo.si/?p=1271</guid>
		<description><![CDATA[Just create an extension to ModelStateDictionary like this: using System; using System.Collections.Generic; using System.Data; using System.Text; using System.Web.Mvc; namespace Avivo.Web.Common { public static class ModelStateDictionaryExtensions { /// &#60;summary&#62; /// Copy validation message from one field to another /// &#60;/summary&#62; /// &#60;param name="modelState"&#62;model state&#60;/param&#62; /// &#60;param name="source"&#62;field to copy from&#60;/param&#62; /// &#60;param name="target"&#62;field to copy to&#60;/param&#62; [...]]]></description>
			<content:encoded><![CDATA[<div style="margin-bottom:30px;">Just create an extension to <strong>ModelStateDictionary </strong>like this:</div>
<pre class="csharp">
using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using System.Web.Mvc;

namespace Avivo.Web.Common
{
  public static class ModelStateDictionaryExtensions
  {
    /// &lt;summary&gt;
    /// Copy validation message from one field to another
    /// &lt;/summary&gt;
    /// &lt;param name="modelState"&gt;model state&lt;/param&gt;
    /// &lt;param name="source"&gt;field to copy from&lt;/param&gt;
    /// &lt;param name="target"&gt;field to copy to&lt;/param&gt;
    public static void CopyMessage(this ModelStateDictionary modelState, string source,
      string target)
    {
      if (modelState.ContainsKey(source) &#038;&#038; modelState.Errors.Count &gt; 0)
      {
        modelState.AddModelError(target, modelState.Errors[0].ErrorMessage);
      }
    }
  }
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://tech.avivo.si/2011/04/how-to-copy-validation-message-from-one-element-to-another-in-asp-net-mvc-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to create custom error 404 in ASP.NET MVC</title>
		<link>http://tech.avivo.si/2011/01/how-to-show-or-create-custom-404-error-page-in-asp-net-mvc/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=how-to-show-or-create-custom-404-error-page-in-asp-net-mvc</link>
		<comments>http://tech.avivo.si/2011/01/how-to-show-or-create-custom-404-error-page-in-asp-net-mvc/#comments</comments>
		<pubDate>Sun, 23 Jan 2011 00:39:04 +0000</pubDate>
		<dc:creator>Avivo</dc:creator>
				<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[404 custom error page]]></category>
		<category><![CDATA[404 error]]></category>
		<category><![CDATA[custom 404 error page]]></category>
		<category><![CDATA[error page]]></category>
		<category><![CDATA[how to create custom 404 error page]]></category>
		<category><![CDATA[microsoft]]></category>

		<guid isPermaLink="false">http://tech.avivo.si/?p=1158</guid>
		<description><![CDATA[Introduction So, whenever an error occurs, you would like to show a custom 404 error page in ASP.NET MVC? This blog post describes how to techically handle and display error page effectively. Reader should have some basic knowledge of setting IIS and ASP .NET MVC project. Error page is displayed when something goes wrong. Page [...]]]></description>
			<content:encoded><![CDATA[<h2>Introduction</h2>
<p>So, whenever an error occurs, you would like to show a custom 404 error page in ASP.NET MVC? This blog post describes how to techically handle and display error page effectively. Reader should have some basic knowledge of setting IIS and ASP .NET MVC project.</p>
<p>Error page is displayed when something goes wrong. Page should inform user about what happened and what he or she should do next. Page should also inform bots, crawlers, spiders not to search any relevent content in there, e.g. Google won&#8217;t display error page as search result. This is handled with HTTP status code known as 404. There are also <a href="http://en.wikipedia.org/wiki/List_of_HTTP_status_codes">other HTTP status codes</a> for specific problems, e.g. for maintenance, for restricted access&#8230;</p>
<h2>Create action and view</h2>
<p>First, create a friendly page for user and set indicator for bots not to handle this page as obvious page. In this case &#8220;Main&#8221; controller with &#8220;Error&#8221; action. Note for IE 5,6: error page should have content larger than 512 bytes otherwise IE will display its own content.</p>
<pre class=csharp>
public class MainController
{
  public ActionResult Error()
  {
    //404 - Tell search engine not to display this page on search results
    Response.StatusCode = 404;
    Response.StatusDescription = "Not Found";
    return View();
  }
}
</pre>
<h2>Register route that eats anything</h2>
<p>Open Global.asax(.cs) in the MVC project and register error page route. Rule should be designed to capture all requests that do not fit in previous route rules. Simple solution: <tt>{*anything}</tt> rule captures any path including slashes, e.g. <em>/shop/mushrooms-123</em>.</p>
<pre class=csharp>
//Somewhere in Global.asax
public static void RegisterRoutes(RouteCollection routes)
{
  //Registered routes
  //...

  //Error route should be registered last
  routes.MapRoute
  (
    "ErrorPage",
    "{*anything}",
    new { controller = "Main", action = "Error" }
  );
}
</pre>
<p>
<strong>Advantage</strong>: no redirects, requested URL string should be kept in browser&#8217;s location bar. For example, when<br />
user requests <em>/shop/mushrooms-123</em> in browser the error page content will be display but the URL will remain original.<br />
The opposite of redirecting and displaying <em>/error</em> in location bar.</p>
<h2>How to handle other errors?</h2>
<p>Other errors in ASP .NET can be handled in <tt>Application_Error</tt> method in <tt>Global.asax</tt>.</p>
<pre class=csharp>
//Somewhere in Global.asax
protected void Application_Error()
{
  //Useful for debugging to get error details
  Exception ex = Server.GetLastError();

  //Redirect to error page
  //Can be "/Main/Error" or "/error" or other route as "ErrorPage" rule eats all
  Response.Redirect(Request.ApplicationPath + "/error/500");
}
</pre>
<h2>Configuration in IIS 7.5</h2>
<p>1. Open IIS Manager. Shortcut: click Start in Windows, type &#8220;inetmgr&#8221; in search box then press Enter.<br />
2. Click on a website on the left side.<br />
3. Select Error Pages on the right side.<br />
4. Configure scenarios for specific status codes, as displayed on screenshots.</p>
<p><a href="http://tech.avivo.si/2011/01/how-to-show-or-create-custom-404-error-page-in-asp-net-mvc/error-page-1/" rel="attachment wp-att-1351"><img src="http://tech.avivo.si/wp-content/uploads/2011/01/error-page-1-600x277.png" alt="" title="Configure Error Pages in IIS (1)" width="600" height="277" class="alignnone size-medium wp-image-1351" /></a></p>
<p><a href="http://tech.avivo.si/2011/01/how-to-show-or-create-custom-404-error-page-in-asp-net-mvc/error-page-2/" rel="attachment wp-att-1352"><img src="http://tech.avivo.si/wp-content/uploads/2011/01/error-page-2-600x277.png" alt="" title="Configure Error Pages in IIS (2)" width="600" height="277" class="alignnone size-medium wp-image-1352" /></a></p>
<h2>Troubleshooting</h2>
<p>Q: Browser displays system error page when I expect custom error page.<br />
A: Configure Error Pages for the website in IIS. Error Pages may differ between websites.</p>
<p>Q: Error handling is defined in web.config but does not work in Windows Server 2008.<br />
A: Try to edit Error Pages directly in IIS (IIS Manager -> Sites -> (website name) -> Error Pages)</p>
<p>Q: Status code 200 OK displays a custom error page but 404 Not Found displays generic IIS error page (yellow box with techical message)<br />
A: Configure Error Pages (see above). &#8220;customErrors&#8221; in web.config may not work as expected.</p>
<p>Q: Can I keep status 200 OK to display error page?<br />
A: It will do the job for users who visually see and understand the content, but may not work for bots (i.e. displaying error page in search result)</p>
<p><!--Simple as that, just register this route (and set right action in your controller) and voila!--><br />
<!--And if you want to catch also <strong>Compilation Errors</strong> (yellow screens with error messages) then you can catch all exceptions in your Global.asax.cs like this:&#8211;></p>
]]></content:encoded>
			<wfw:commentRss>http://tech.avivo.si/2011/01/how-to-show-or-create-custom-404-error-page-in-asp-net-mvc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to trim leading and trailing HTML spaces in C#</title>
		<link>http://tech.avivo.si/2010/12/how-to-trim-leading-and-trailing-html-spaces-in-c/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=how-to-trim-leading-and-trailing-html-spaces-in-c</link>
		<comments>http://tech.avivo.si/2010/12/how-to-trim-leading-and-trailing-html-spaces-in-c/#comments</comments>
		<pubDate>Mon, 13 Dec 2010 12:27:52 +0000</pubDate>
		<dc:creator>developer</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[regex]]></category>
		<category><![CDATA[remove trailing and leading html spaces]]></category>
		<category><![CDATA[trim]]></category>

		<guid isPermaLink="false">http://tech.avivo.si/?p=948</guid>
		<description><![CDATA[Some HTML WYSIWYG editors create &#8216;br&#8217; tags or leave &#8216;&#38;nbsp;&#8217; garbage spaces when no content is entered. Described TrimWhiteSpaces method is useful when you need to determine if user left blank content in WYSIWYG editor or if you just want to clean HTML code. TrimWhiteSpaces accepts raw HTML content and removes white spaces, tabs, new [...]]]></description>
			<content:encoded><![CDATA[<p>Some HTML WYSIWYG editors create &#8216;br&#8217; tags or leave &#8216;&amp;nbsp;&#8217; garbage spaces when no content is entered. Described <strong>TrimWhiteSpaces </strong>method is useful when you need to determine if user left blank content in WYSIWYG editor or if you just want to clean HTML code.</p>
<p><strong>TrimWhiteSpaces</strong> accepts raw HTML content and removes white spaces, tabs, new line characters, &#8216;br&#8217; tags and &#8216;&amp;nbsp;&#8217; chunks from before and after the actual content.</p>
<pre class=csharp>
public static string TrimWhiteSpaces(string html)
{
  string result = html;

  //Remove leading spaces
  result = Regex.Replace(result, @"<span style="color: red;">^(?&lt;leading&gt;(\s|\r|\n|\&lt;br\s*/?\&gt;|&amp;nbsp;)*)</span>", "",
RegexOptions.IgnoreCase);

  //Remove trailing spaces
  result = Regex.Replace(result, @"<span style="color: red;">(?&lt;trailing&gt;(\s|\r|\n|\&lt;br\s*/?\&gt;|&amp;nbsp;)*)$</span>", "",
RegexOptions.IgnoreCase);

  return result;
}
</pre>
<div style="margin-top:20px;">
<strong>Example:</strong>
</div>
<div style="margin-top:20px;">
<strong>Input:</strong></p>
<pre><span style="color: red;">&amp;nbsp;&lt;br /&gt;&lt;BR   &gt;&lt;BR&gt; &amp;nbsp;
&amp;nbsp;&amp;nbsp;&lt;br /&gt;</span><span style="color: blue;">
&lt;p&gt;Lorem ipsum dolor sit amet, consectetur adipiscing elit.&lt;/p&gt;
&amp;nbsp;&amp;nbsp;&lt;br /&gt;
&lt;p&gt;Pellentesque lorem neque, accumsan eget euismod ut, tristique et odio.&lt;/p&gt;</span>
<span style="color: red;">&amp;nbsp;&lt;br /&gt; &lt;br&gt;
&amp;nbsp;</span>
</pre>
</div>
<div style="margin-top:20px;">
<strong>Output:</strong></p>
<pre class=csharp>
<span style="color: blue;">
&lt;p&gt;Lorem ipsum dolor sit amet, consectetur adipiscing elit.&lt;/p&gt;
&amp;nbsp;&amp;nbsp;&lt;br /&gt;
&lt;p&gt;Pellentesque lorem neque, accumsan eget euismod ut, tristique et odio.&lt;/p&gt;
</span>
</pre>
</div>
]]></content:encoded>
			<wfw:commentRss>http://tech.avivo.si/2010/12/how-to-trim-leading-and-trailing-html-spaces-in-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Parsing URL query string into key-value pairs in C#</title>
		<link>http://tech.avivo.si/2010/12/parsing-url-query-string-into-key-value-pairs-in-c/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=parsing-url-query-string-into-key-value-pairs-in-c</link>
		<comments>http://tech.avivo.si/2010/12/parsing-url-query-string-into-key-value-pairs-in-c/#comments</comments>
		<pubDate>Fri, 03 Dec 2010 12:08:31 +0000</pubDate>
		<dc:creator>Avivo</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[Programming Techniques]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[key-value pairs from query string]]></category>
		<category><![CDATA[parsing query string]]></category>
		<category><![CDATA[query string]]></category>
		<category><![CDATA[url]]></category>

		<guid isPermaLink="false">http://tech.avivo.si/?p=917</guid>
		<description><![CDATA[Imagine you have URL something like this: http://www.yourdomain.com?param1=value1&#38;param2=value2&#38;param3=value3&#38;param4=value4 and you want to get key-value pairs such as {&#8220;param1&#8243;, &#8220;param2&#8243;, &#8220;param3&#8243;, &#8220;param4&#8243;} {&#8220;value1&#8243;, &#8220;value2&#8243;, &#8220;value3&#8243;, &#8220;value4&#8243;} It is easy to do using system function: using System.Collections.Specialized; NameValueCollection query = HttpUtility.ParseQueryString(queryString); Response.Write(query["param1"]);]]></description>
			<content:encoded><![CDATA[<p>Imagine you have URL something like this:</p>
<p><strong>http://www.yourdomain.com?param1=value1&amp;param2=value2&amp;param3=value3&amp;param4=value4</strong></p>
<p>and you want to get key-value pairs such as</p>
<ul>
<li>{&#8220;param1&#8243;, &#8220;param2&#8243;, &#8220;param3&#8243;, &#8220;param4&#8243;}</li>
<li>{&#8220;value1&#8243;, &#8220;value2&#8243;, &#8220;value3&#8243;, &#8220;value4&#8243;}</li>
</ul>
<p>It is easy to do using system function:</p>
<pre class=charp>
using System.Collections.Specialized;
NameValueCollection query = HttpUtility.ParseQueryString(queryString);
Response.Write(query["param1"]);
</pre>
]]></content:encoded>
			<wfw:commentRss>http://tech.avivo.si/2010/12/parsing-url-query-string-into-key-value-pairs-in-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Compiler Error Message: CS0016: Could not write to output file &#8211; Temporary ASP.NET Files &#8211; Access is denied</title>
		<link>http://tech.avivo.si/2010/11/compiler-error-message-cs0016-could-not-write-to-output-file-temporary-asp-net-files-access-is-denied/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=compiler-error-message-cs0016-could-not-write-to-output-file-temporary-asp-net-files-access-is-denied</link>
		<comments>http://tech.avivo.si/2010/11/compiler-error-message-cs0016-could-not-write-to-output-file-temporary-asp-net-files-access-is-denied/#comments</comments>
		<pubDate>Thu, 11 Nov 2010 13:30:31 +0000</pubDate>
		<dc:creator>Avivo</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[System administration]]></category>
		<category><![CDATA[Access is denied]]></category>
		<category><![CDATA[App_GlobalResources.xxxxxxx.dll]]></category>
		<category><![CDATA[Compiler Error Message]]></category>
		<category><![CDATA[CS0016: Could not write to output file]]></category>
		<category><![CDATA[iis 7 error]]></category>
		<category><![CDATA[iis error]]></category>
		<category><![CDATA[v2.0.50727\Temporary ASP.NET Files]]></category>

		<guid isPermaLink="false">http://tech.avivo.si/?p=808</guid>
		<description><![CDATA[Everything was working perfectly and then suddenly during ASP.NET (MVC) development you got this error from your IIS 7 server (in our case from Windows 7 64-bit): Compiler Error Message: CS0016: Could not write to output file ‘c:\WINDOWS\Microsoft.NET\Framework64\v2.0.50727\Temporary ASP.NET Files\myapp\xxxxx\xxxxx\App_GlobalResources.xxxxxxx.dll’ — &#8216;Access is denied.&#8217; So, what goes wrong? You don&#8217;t know because it was working [...]]]></description>
			<content:encoded><![CDATA[<p>Everything was working perfectly and then suddenly during ASP.NET (MVC) development you got this error from your IIS 7 server (in our case from Windows 7 64-bit):<br />
<strong><span style="color: #ff0000;">Compiler Error Message: CS0016: Could not write to output file ‘c:\WINDOWS\Microsoft.NET\Framework64\v2.0.50727\Temporary ASP.NET Files\myapp\xxxxx\xxxxx\App_GlobalResources.xxxxxxx.dll’ — &#8216;Access is denied.&#8217;</span></strong><br />
So, what goes wrong? You don&#8217;t know because it was working perfectly previous day, it is also compiles OK but not working anymore on your IIS webserver and, all you got, is yellow screen with this error message.</p>
<h4 style="margin-bottom: 25px;"><strong>We searched a little bit and found that the problem appeared because the permission were lost on following Temporary folders:</strong></h4>
<pre style="margin-bottom: 25px;" lang="text">C:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\

C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\

C:\Windows\Microsoft.NET\Framework64\v2.0.50727\Temporary ASP.NET Files\

C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\

C:\Windows\Temp
</pre>
<h4><strong>Recipe</strong></h4>
<ul>
<li>Gave a full permission to NETWORK SERVICE user to these folders (extreme case is to give full permission to Everyone user to these folders &#8211; do this only it doesn&#8217;t work)</li>
<li>Restart IIS using <strong>iisreset </strong>command</li>
</ul>
<p>IIS started to serve pages again&#8230;.</p>
]]></content:encoded>
			<wfw:commentRss>http://tech.avivo.si/2010/11/compiler-error-message-cs0016-could-not-write-to-output-file-temporary-asp-net-files-access-is-denied/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

