<?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>Jan Jonas&#039; blog</title> <atom:link href="http://blog.janjonas.net/feed" rel="self" type="application/rss+xml" /><link>http://blog.janjonas.net</link> <description>Howtos &#38; Tutorials</description> <lastBuildDate>Thu, 10 May 2012 21:07:26 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.2</generator> <item><title>ISA Server 2006 as Reverse Web Caching Proxy: Analyze &#8220;Object source&#8221; and &#8220;Cache Info&#8221; fields</title><link>http://blog.janjonas.net/2012-05-10/isa-server-2006-reverse-web-caching-proxy-object-source-cache-info</link> <comments>http://blog.janjonas.net/2012-05-10/isa-server-2006-reverse-web-caching-proxy-object-source-cache-info#comments</comments> <pubDate>Thu, 10 May 2012 21:05:53 +0000</pubDate> <dc:creator>Jan Jonas</dc:creator> <category><![CDATA[Howto]]></category> <category><![CDATA[System administration]]></category> <category><![CDATA[ISA Server 2006]]></category> <category><![CDATA[Microsoft]]></category> <category><![CDATA[proxy]]></category> <guid
isPermaLink="false">http://blog.janjonas.net/?p=1592</guid> <description><![CDATA[When publishing content from a web server that is behind a ISA 2006 firewall, the ISA can be configured as Reverse Web Caching proxy, i.e. the ISA caches responses from the web server(s) and sends the cached content to the clients instead of requesting the content from the web servers again (see &#8220;Reverse proxy&#8221; on [...]
Related posts:<ol><li><a
href='http://blog.janjonas.net/2012-01-28/asp_net-disable-browser-proxy-caching-aspx-resources' rel='bookmark' title='ASP.NET: Disable browser and proxy caching for aspx resources'>ASP.NET: Disable browser and proxy caching for aspx resources</a></li><li><a
href='http://blog.janjonas.net/2010-10-09/debian-ubuntu-apache_2-transparent-reverse-proxy-mod_proxy' rel='bookmark' title='Debian/Ubuntu &amp; Apache 2: Transparent reverse proxy with mod_proxy'>Debian/Ubuntu &#038; Apache 2: Transparent reverse proxy with mod_proxy</a></li><li><a
href='http://blog.janjonas.net/2010-01-04/apaches-mod_rewrite-mod_proxy-use-reverse-proxy-request-headers-for-rewrite-rules' rel='bookmark' title='Apache&#8217;s mod_rewrite &amp; mod_proxy: Use &#8220;Reverse Proxy Request Headers&#8221; for rewrite rules'>Apache&#8217;s mod_rewrite &#038; mod_proxy: Use &#8220;Reverse Proxy Request Headers&#8221; for rewrite rules</a></li></ol>]]></description> <content:encoded><![CDATA[<p>When publishing content from a web server that is behind a ISA 2006 firewall, the ISA can be configured as Reverse Web Caching proxy, i.e. the ISA caches responses from the web server(s) and sends the cached content to the clients instead of requesting the content from the web servers again (see &#8220;<a
href="http://en.wikipedia.org/wiki/Reverse_proxy" target="_blank">Reverse proxy</a>&#8221; on Wikipedia). On the one hand this could reduce the load of the web severs and on the other hand enables the clients to view content even if the web servers are offline.</p><p>In this Reverse Web Caching scenario it could be interesting to analyze if a specific request was forwarded to the web server(s) and, in this case, if the web server&#8217;s response is cached by the proxy for future client requests or if the proxy delivers content from its cache.</p><p>Fortunately, the ISA server provides detailed ISA Server Web proxy log entries that include the &#8220;Object Source&#8221; and &#8220;Cache Info&#8221; fields (see <a
href="http://msdn.microsoft.com/en-us/library/aa503433.aspx" target="_blank">http://msdn.microsoft.com/en-us/library/aa503433.aspx</a>):</p><ul><li>Object Source<br
/><blockquote><p>The type of source that was used to retrieve the current object. A table of some possible values is provided in Object Source Values.</p></blockquote></li><li>Cache Info<br
/><blockquote><p>A number reflecting the cache status of the object, which indicates the reasons why the object was or was not cached. The number logged is the sum of the values for all the conditions that are met. A table of the possible values is provided in Cache Information Values.</p></blockquote></li></ul><p>The &#8220;Object source&#8221; provides information about whether the object was retrieved in the cache or not (see <a
href="http://msdn.microsoft.com/en-us/library/aa503433.aspx#_isa_object_source_values" target="_blank">possible value</a>). The &#8220;Cache Info&#8221; field is a bit mask that includes various cache information (see <a
href="http://msdn.microsoft.com/en-us/library/aa503433.aspx#_isa_cache_info_values" target="_blank">http://msdn.microsoft.com/en-us/library/aa503433.aspx#_isa_cache_info_values</a>); the most interesting values are:</p><ul><li><em>0&#215;00000001</em>: Request should not be served from the cache.</li><li><em>0&#215;40000000</em>: Response should not be cached.</li></ul><p>Related posts:<ol><li><a
href='http://blog.janjonas.net/2012-01-28/asp_net-disable-browser-proxy-caching-aspx-resources' rel='bookmark' title='ASP.NET: Disable browser and proxy caching for aspx resources'>ASP.NET: Disable browser and proxy caching for aspx resources</a></li><li><a
href='http://blog.janjonas.net/2010-10-09/debian-ubuntu-apache_2-transparent-reverse-proxy-mod_proxy' rel='bookmark' title='Debian/Ubuntu &amp; Apache 2: Transparent reverse proxy with mod_proxy'>Debian/Ubuntu &#038; Apache 2: Transparent reverse proxy with mod_proxy</a></li><li><a
href='http://blog.janjonas.net/2010-01-04/apaches-mod_rewrite-mod_proxy-use-reverse-proxy-request-headers-for-rewrite-rules' rel='bookmark' title='Apache&#8217;s mod_rewrite &amp; mod_proxy: Use &#8220;Reverse Proxy Request Headers&#8221; for rewrite rules'>Apache&#8217;s mod_rewrite &#038; mod_proxy: Use &#8220;Reverse Proxy Request Headers&#8221; for rewrite rules</a></li></ol></p>]]></content:encoded> <wfw:commentRss>http://blog.janjonas.net/2012-05-10/isa-server-2006-reverse-web-caching-proxy-object-source-cache-info/feed</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Crashplan 3.8.2010: Fix &#8220;CrashPlan PRO Server failed to initialize &#8211; error 4001&#8243; on Linux</title><link>http://blog.janjonas.net/2012-04-30/crashplan-pro-server-failed-initialize-error-4001-linux</link> <comments>http://blog.janjonas.net/2012-04-30/crashplan-pro-server-failed-initialize-error-4001-linux#comments</comments> <pubDate>Mon, 30 Apr 2012 20:46:28 +0000</pubDate> <dc:creator>Jan Jonas</dc:creator> <category><![CDATA[Howto]]></category> <category><![CDATA[System administration]]></category> <category><![CDATA[CrashPlan]]></category> <category><![CDATA[Linux]]></category> <guid
isPermaLink="false">http://blog.janjonas.net/?p=1595</guid> <description><![CDATA[For any reason my Linux CrashPlan PRO Server (version 3.8.2010) crashed. The CrashPlan manager web user interface shows the error CrashPlan PRO Server failed to initialize &#8211; error 4001 After restarting the CrashPlan PRO Server the log (/var/log/proserver/com_backup42_app.log.0) shows the following error: [...] org.h2.jdbc.JdbcSQLException: File corrupted while reading record: &#34;index not found 286&#34;. Possible solution: [...]
Related posts:<ol><li><a
href='http://blog.janjonas.net/2011-03-05/crashplan_pro-windows-connect-remote-headless-client-linux' rel='bookmark' title='CrashPlan PRO &amp; Windows: How to connect to a remote (headless) CrashPlan PRO client running on Linux'>CrashPlan PRO &#038; Windows: How to connect to a remote (headless) CrashPlan PRO client running on Linux</a></li><li><a
href='http://blog.janjonas.net/2011-01-10/eclipse-helios-subversive-installing-svn-connector-failed' rel='bookmark' title='Eclipse 3.6.1 (Helios) &amp; Subversive: Installing SVN connector failed'>Eclipse 3.6.1 (Helios) &#038; Subversive: Installing SVN connector failed</a></li><li><a
href='http://blog.janjonas.net/2010-01-03/fit-pc2-fixed-random-system-freezes-on-linux' rel='bookmark' title='fit-PC2: Fixed (random) system freezes on Linux'>fit-PC2: Fixed (random) system freezes on Linux</a></li></ol>]]></description> <content:encoded><![CDATA[<p>For any reason my Linux CrashPlan PRO Server (version 3.8.2010) crashed. The CrashPlan manager web user interface shows the error</p><blockquote><p>CrashPlan PRO Server failed to initialize &#8211; error 4001</p></blockquote><p>After restarting the CrashPlan PRO Server the log (<em>/var/log/proserver/com_backup42_app.log.0</em>) shows the following error:</p><div
class="wp_syntax"><div
class="code"><pre class="log" style="font-family:monospace;">[...]
org.h2.jdbc.JdbcSQLException: File corrupted while reading record: &quot;index not found 286&quot;. Possible solution: use the recovery tool [90030-131]
        at org.h2.message.DbException.getJdbcSQLException(DbException.java:316)
        at org.h2.message.DbException.get(DbException.java:167)
        at org.h2.message.DbException.get(DbException.java:144)
        at org.h2.store.PageStore.getPage(PageStore.java:502)
        at org.h2.index.PageDataIndex.getPage(PageDataIndex.java:212)
        at org.h2.index.PageDataNode.getLastKey(PageDataNode.java:221)
        at org.h2.index.PageDataNode.getLastKey(PageDataNode.java:221)
        at org.h2.index.PageDataIndex.&lt;init&gt;(PageDataIndex.java:74)
        at org.h2.table.TableData.&lt;init&gt;(TableData.java:78)
        at org.h2.store.PageStore.addMeta(PageStore.java:1313)
        at org.h2.store.PageStore.readMetaData(PageStore.java:1240)
        at org.h2.store.PageStore.recover(PageStore.java:1046)
        at org.h2.store.PageStore.openExisting(PageStore.java:301)
        at org.h2.store.PageStore.open(PageStore.java:259)
        at org.h2.engine.Database.getPageStore(Database.java:2014)
        at org.h2.engine.Database.open(Database.java:527)
        at org.h2.engine.Database.openDatabase(Database.java:203)
        at org.h2.engine.Database.&lt;init&gt;(Database.java:198)
        at org.h2.engine.Engine.openSession(Engine.java:56)
        at org.h2.engine.Engine.openSession(Engine.java:141)
        at org.h2.engine.Engine.getSession(Engine.java:120)
        at org.h2.engine.Session.createSession(Session.java:119)
        at org.h2.engine.SessionRemote.connectEmbeddedOrServer(SessionRemote.java:235)
        at org.h2.engine.SessionRemote.createSession(SessionRemote.java:213)
        at org.h2.jdbc.JdbcConnection.&lt;init&gt;(JdbcConnection.java:110)
        at org.h2.jdbc.JdbcConnection.&lt;init&gt;(JdbcConnection.java:94)
        at org.h2.Driver.connect(Driver.java:58)
        at java.sql.DriverManager.getConnection(DriverManager.java:582)
        at java.sql.DriverManager.getConnection(DriverManager.java:185)
        at com.backup42.server.DbVerifierForH2.getConnection(DbVerifierForH2.java:92)
        at com.backup42.server.DbVerifierForH2.verifyDb(DbVerifierForH2.java:33)
        at com.backup42.main.CPServer.main(CPServer.java:361)
[...]</pre></div></div><p>Fortunately the CrashPlan PRO server frequently creates dumps of its internal database and I was able to restore the server&#8217;s database from such a dump with CrashPlan&#8217;s <em>restore_database.sh</em> script (see <a
href="http://support.crashplanpro.com/doku.php/reference/proserver/command_line_tools#restore_database" target="_blank">CrashPlan Pro support</a>).</p><p>The location of the database dumps could be found in <em>/var/log/proserver/app.log</em>:</p><div
class="wp_syntax"><div
class="code"><pre class="log" style="font-family:monospace;">[...]
DBDumpDir   = /var/opt/proserver/dumps
[...]</pre></div></div><p>To restore the database execute the <em>restore_database.sh</em> and pass a dump file as argument:</p><div
class="wp_syntax"><div
class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>proserver<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>restore_database.sh <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>proserver<span style="color: #000000; font-weight: bold;">/</span>dumps<span style="color: #000000; font-weight: bold;">/</span>proserver-db_<span style="color: #7a0874; font-weight: bold;">&#91;</span>...<span style="color: #7a0874; font-weight: bold;">&#93;</span>.sql.gz</pre></div></div><p>This script shuts down the CrashPlan PRO server before restoring the database and restarts the server after the restore is completed.</p><p>After the CrashPlan server is up and running again the CrashPlan manager web user interface shows the message</p><blockquote><p>Your PRO Server is running from a newly imported database. The old database has been preserved within: /opt/proserver/db.bak<br/>This message will be displayed until that backup directory is manually moved to a safe location or deleted.</p></blockquote><p>Related posts:<ol><li><a
href='http://blog.janjonas.net/2011-03-05/crashplan_pro-windows-connect-remote-headless-client-linux' rel='bookmark' title='CrashPlan PRO &amp; Windows: How to connect to a remote (headless) CrashPlan PRO client running on Linux'>CrashPlan PRO &#038; Windows: How to connect to a remote (headless) CrashPlan PRO client running on Linux</a></li><li><a
href='http://blog.janjonas.net/2011-01-10/eclipse-helios-subversive-installing-svn-connector-failed' rel='bookmark' title='Eclipse 3.6.1 (Helios) &amp; Subversive: Installing SVN connector failed'>Eclipse 3.6.1 (Helios) &#038; Subversive: Installing SVN connector failed</a></li><li><a
href='http://blog.janjonas.net/2010-01-03/fit-pc2-fixed-random-system-freezes-on-linux' rel='bookmark' title='fit-PC2: Fixed (random) system freezes on Linux'>fit-PC2: Fixed (random) system freezes on Linux</a></li></ol></p>]]></content:encoded> <wfw:commentRss>http://blog.janjonas.net/2012-04-30/crashplan-pro-server-failed-initialize-error-4001-linux/feed</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>WordPress &amp; jQuery: Fix JavaScript error &#8220;$ is not a function&#8221;</title><link>http://blog.janjonas.net/2012-04-15/wordpress-jquery-fix-javascript-error-is-not-a-function</link> <comments>http://blog.janjonas.net/2012-04-15/wordpress-jquery-fix-javascript-error-is-not-a-function#comments</comments> <pubDate>Sun, 15 Apr 2012 17:06:14 +0000</pubDate> <dc:creator>Jan Jonas</dc:creator> <category><![CDATA[Howto]]></category> <category><![CDATA[Programming]]></category> <category><![CDATA[JavaScript]]></category> <category><![CDATA[jQuery]]></category> <category><![CDATA[Wordpress]]></category> <guid
isPermaLink="false">http://blog.janjonas.net/?p=1579</guid> <description><![CDATA[When using jQuery in WordPress you might be surprised by a $ is not a function JavaScript error. For example, in a default WordPress 3.3.1 installation, the following JavaScript code leads to this error: $&#40;document&#41;.ready&#40;function&#40;&#41; &#123; console.log&#40;$&#40;&#34;body&#34;&#41;&#41;; &#125;&#41;; The reason is, that WordPress by default uses jQuery&#8217;s &#8220;no conflict mode&#8221; to avoid compatibility problems with [...]
Related posts:<ol><li><a
href='http://blog.janjonas.net/2011-07-13/jquery-disable-browser-cache-all-ajax-requests' rel='bookmark' title='jQuery: Disable (browser) cache for all AJAX requests'>jQuery: Disable (browser) cache for all AJAX requests</a></li><li><a
href='http://blog.janjonas.net/2011-08-07/asp_net-mvc_3-jquery-ajax-submit-ajax-form-supporting-unobtrusive-client-side-validation-and-server-side-validation' rel='bookmark' title='ASP.NET MVC 3: Using jQuery .ajax() function to submit Ajax Form supporting (unobtrusive) Client Side Validation and Server Side Validation'>ASP.NET MVC 3: Using jQuery .ajax() function to submit Ajax Form supporting (unobtrusive) Client Side Validation and Server Side Validation</a></li><li><a
href='http://blog.janjonas.net/2011-12-11/asp-net-mvc3-custom-error-pages-non-ajax-requests-jquery-ajax-requests' rel='bookmark' title='ASP.NET MVC 3: Set up custom error pages to handle errors in &#8220;non-AJAX&#8221; requests and jQuery AJAX requests'>ASP.NET MVC 3: Set up custom error pages to handle errors in &#8220;non-AJAX&#8221; requests and jQuery AJAX requests</a></li></ol>]]></description> <content:encoded><![CDATA[<p>When using jQuery in WordPress you might be surprised by a</p><blockquote><p> $ is not a function</p></blockquote><p>JavaScript error.</p><p>For example, in a default WordPress 3.3.1 installation, the following JavaScript code leads to this error:</p><div
class="wp_syntax"><div
class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;body&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div><p>The reason is, that WordPress by default uses jQuery&#8217;s &#8220;no conflict mode&#8221; to avoid compatibility problems with other JavaScript libraries that might could also use the <em>$</em> variable. In detail, the jQuery script source included in WordPress activates this mode by calling <a
href="http://api.jquery.com/jQuery.noConflict/" target="_blank"><em>jQuery.noConflict()</em></a> (for WordPress 3.3.1 see line 5 in <a
href="http://core.trac.wordpress.org/browser/tags/3.3.1/wp-includes/js/jquery/jquery.js#L5" target="_blank">http://core.trac.wordpress.org/browser/tags/3.3.1/wp-includes/js/jquery/jquery.js#L5</a>).</p><p>To fix the error replace jQuery&#8217;s <em>$</em> shortcut by <em>jQuery</em>. Optionally, you can add a <em>$</em> parameter your handler functions to define the <em>$</em> shortcut inside the functions:</p><div
class="wp_syntax"><div
class="code"><pre class="javascript" style="font-family:monospace;">jQuery<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;body&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div><p>Related posts:<ol><li><a
href='http://blog.janjonas.net/2011-07-13/jquery-disable-browser-cache-all-ajax-requests' rel='bookmark' title='jQuery: Disable (browser) cache for all AJAX requests'>jQuery: Disable (browser) cache for all AJAX requests</a></li><li><a
href='http://blog.janjonas.net/2011-08-07/asp_net-mvc_3-jquery-ajax-submit-ajax-form-supporting-unobtrusive-client-side-validation-and-server-side-validation' rel='bookmark' title='ASP.NET MVC 3: Using jQuery .ajax() function to submit Ajax Form supporting (unobtrusive) Client Side Validation and Server Side Validation'>ASP.NET MVC 3: Using jQuery .ajax() function to submit Ajax Form supporting (unobtrusive) Client Side Validation and Server Side Validation</a></li><li><a
href='http://blog.janjonas.net/2011-12-11/asp-net-mvc3-custom-error-pages-non-ajax-requests-jquery-ajax-requests' rel='bookmark' title='ASP.NET MVC 3: Set up custom error pages to handle errors in &#8220;non-AJAX&#8221; requests and jQuery AJAX requests'>ASP.NET MVC 3: Set up custom error pages to handle errors in &#8220;non-AJAX&#8221; requests and jQuery AJAX requests</a></li></ol></p>]]></content:encoded> <wfw:commentRss>http://blog.janjonas.net/2012-04-15/wordpress-jquery-fix-javascript-error-is-not-a-function/feed</wfw:commentRss> <slash:comments>1</slash:comments> </item> <item><title>ASP.NET How-To: Create User Control library by compiling User Controls into .dll files</title><link>http://blog.janjonas.net/2012-04-06/asp_net-howto-user-control-library-compile-dll-file</link> <comments>http://blog.janjonas.net/2012-04-06/asp_net-howto-user-control-library-compile-dll-file#comments</comments> <pubDate>Fri, 06 Apr 2012 21:49:44 +0000</pubDate> <dc:creator>Jan Jonas</dc:creator> <category><![CDATA[Howto]]></category> <category><![CDATA[Programming]]></category> <category><![CDATA[.NET]]></category> <category><![CDATA[ASP.NET]]></category> <guid
isPermaLink="false">http://blog.janjonas.net/?p=1553</guid> <description><![CDATA[This blog post shows how to create a User Control library (a .dll file containing User Controls). To reuse the contained User Controls in other ASP.NET web projects you just need to add a reference to this .dll file and register a tag prefix (as shown at the end of this post). First, we need [...]
Related posts:<ol><li><a
href='http://blog.janjonas.net/2011-06-18/aspnet-membership-provider-changing-user-password-without-knowing-old' rel='bookmark' title='ASP.NET Membership Provider: Changing user password without knowing the old one'>ASP.NET Membership Provider: Changing user password without knowing the old one</a></li><li><a
href='http://blog.janjonas.net/2011-11-26/asp_net-mvc_3-remix-library-add-controller-actions-mixins' rel='bookmark' title='ASP.NET MVC 3: Use re-mix library to add controller actions with mixins'>ASP.NET MVC 3: Use re-mix library to add controller actions with mixins</a></li><li><a
href='http://blog.janjonas.net/2012-01-15/asp_net-mvc_3-remix-library-add-controller-actions-mixins-part2' rel='bookmark' title='ASP.NET MVC 3: Use re-mix library to add controller actions with mixins &#8211; Part 2'>ASP.NET MVC 3: Use re-mix library to add controller actions with mixins &#8211; Part 2</a></li></ol>]]></description> <content:encoded><![CDATA[<p>This blog post shows how to create a User Control library (a <em>.dll</em> file containing User Controls). To reuse the contained User Controls in other ASP.NET web projects you just need to add a reference to this <em>.dll</em> file and register a tag prefix (as shown at the end of this post).</p><p>First, we need the following base class for the User Controls that should be included in the library:</p><div
class="wp_syntax"><div
class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> abstract <span style="color: #6666cc; font-weight: bold;">class</span> UserControlBase <span style="color: #008000;">:</span> <span style="color: #000000;">System.<span style="color: #0000FF;">Web</span><span style="color: #008000;">.</span><span style="color: #0000FF;">UI</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">UserControl</span>
<span style="color: #008000;">&#123;</span>
  <span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">void</span> FrameworkInitialize<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">base</span><span style="color: #008000;">.</span><span style="color: #0000FF;">FrameworkInitialize</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #6666cc; font-weight: bold;">string</span> content<span style="color: #008000;">;</span>
&nbsp;
    var resourceName <span style="color: #008000;">=</span> GetType<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">FullName</span> <span style="color: #008000;">+</span> <span style="color: #666666;">&quot;.ascx&quot;</span><span style="color: #008000;">;</span>
    var stream <span style="color: #008000;">=</span> Assembly<span style="color: #008000;">.</span><span style="color: #0000FF;">GetExecutingAssembly</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetManifestResourceStream</span><span style="color: #008000;">&#40;</span>resourceName<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>stream <span style="color: #008000;">==</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
      <span style="color: #0600FF; font-weight: bold;">throw</span> <span style="color: #008000;">new</span> InvalidOperationException<span style="color: #008000;">&#40;</span>
        <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Format</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Loading resource '{0}' failed&quot;</span>, resourceName<span style="color: #008000;">&#41;</span>
      <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008000;">&#40;</span>var reader <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> StreamReader<span style="color: #008000;">&#40;</span>stream<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
    content <span style="color: #008000;">=</span> reader<span style="color: #008000;">.</span><span style="color: #0000FF;">ReadToEnd</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    var userControl <span style="color: #008000;">=</span> Page<span style="color: #008000;">.</span><span style="color: #0000FF;">ParseControl</span><span style="color: #008000;">&#40;</span>content<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>userControl <span style="color: #008000;">==</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
      <span style="color: #0600FF; font-weight: bold;">throw</span> <span style="color: #008000;">new</span> InvalidOperationException<span style="color: #008000;">&#40;</span>
        <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Format</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Parsing user control in resource '{0}' failed&quot;</span>, resourceName<span style="color: #008000;">&#41;</span>
      <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
    Controls<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>userControl<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    WireControls<span style="color: #008000;">&#40;</span>userControl<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  <span style="color: #008000;">&#125;</span>
&nbsp;
  <span style="color: #0600FF; font-weight: bold;">protected</span> abstract <span style="color: #6666cc; font-weight: bold;">void</span> WireControls<span style="color: #008000;">&#40;</span><span style="color: #000000;">System.<span style="color: #0000FF;">Web</span><span style="color: #008000;">.</span><span style="color: #0000FF;">UI</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">Control</span> userControl<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div><p>Next we remove the User Control&#8217;s designer file (the <em>.ascx.designer.cs</em> file) and remove all attributes except the <em>Language</em> attribute from the <em>&lt;Control&gt;</em> tag in the User Control&#8217;s <em>.ascx</em> file.</p><p>The exemplary User Control in this blog post contains a <em>Literal</em> control that shows the current time; the <em>.ascx</em> file looks as follows:</p><div
class="wp_syntax"><div
class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">&lt;%</span>@ Control Language<span style="color: #008000;">=</span><span style="color: #666666;">&quot;C#&quot;</span> <span style="color: #008000;">%&gt;</span>
&nbsp;
<span style="color: #008000;">&lt;</span>asp<span style="color: #008000;">:</span>Literal ID<span style="color: #008000;">=</span><span style="color: #666666;">&quot;Output&quot;</span> runat<span style="color: #008000;">=</span><span style="color: #666666;">&quot;server&quot;</span><span style="color: #008000;">&gt;&lt;/</span>asp<span style="color: #008000;">:</span>Literal<span style="color: #008000;">&gt;</span></pre></div></div><p>In the User Control&#8217;s code behind file we use the above defined <em>UserControlBase</em> class as parent class:</p><div
class="wp_syntax"><div
class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">partial</span> <span style="color: #6666cc; font-weight: bold;">class</span> MyUserControl <span style="color: #008000;">:</span> UserControlBase
<span style="color: #008000;">&#123;</span>
  <span style="color: #0600FF; font-weight: bold;">private</span> Literal output<span style="color: #008000;">;</span>
&nbsp;
  <span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #6666cc; font-weight: bold;">void</span> Page_Load<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> sender, EventArgs e<span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
    output<span style="color: #008000;">.</span><span style="color: #0000FF;">Text</span> <span style="color: #008000;">=</span> DateTime<span style="color: #008000;">.</span><span style="color: #0000FF;">Now</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ToString</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  <span style="color: #008000;">&#125;</span>
&nbsp;
  <span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">void</span> WireControls<span style="color: #008000;">&#40;</span><span style="color: #000000;">System.<span style="color: #0000FF;">Web</span><span style="color: #008000;">.</span><span style="color: #0000FF;">UI</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">Control</span> userControl<span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
    output <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span>Literal<span style="color: #008000;">&#41;</span>userControl<span style="color: #008000;">.</span><span style="color: #0000FF;">FindControl</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;output&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></div></div><p>Please note: Since there is no designer file we need to create private fields for the controls and assign them manually by overriding the <em>WireControls</em> method of our <em>UserControlBase</em> parent class.</p><p>Before building the project to create the <em>.dll</em> library file we need to set the the build action for the <em>.ascx</em> to &#8220;<em>Embedded Resource</em>&#8220;.</p><p>You can download the Visual Studio 2010 project containing all the source code of the User Control library project <a
href="http://blog.janjonas.net/wp-content/uploads/2012/04/vs_2010-UserControl-Dll-File.zip">here</a>.</p><p>To include the User Control in any other ASP.NET project just add a reference to the (library) <em>.dll</em> file and add the User Control as follows on any ASP.NET page:</p><div
class="wp_syntax"><div
class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">&#91;</span><span style="color: #008000;">...</span><span style="color: #008000;">&#93;</span>
<span style="color: #008000;">&lt;%</span>@ Register Assembly<span style="color: #008000;">=</span><span style="color: #666666;">&quot;UserControl-Dll-File&quot;</span> TagPrefix<span style="color: #008000;">=</span><span style="color: #666666;">&quot;uc&quot;</span> <span style="color: #0600FF; font-weight: bold;">Namespace</span><span style="color: #008000;">=</span><span style="color: #666666;">&quot;UserControl_Dll_File&quot;</span> <span style="color: #008000;">%&gt;</span>
<span style="color: #008000;">&lt;</span>uc<span style="color: #008000;">:</span>MyUserControl ID<span style="color: #008000;">=</span><span style="color: #666666;">&quot;WebUserControl1&quot;</span> runat<span style="color: #008000;">=</span><span style="color: #666666;">&quot;server&quot;</span><span style="color: #008000;">&gt;&lt;/</span>uc<span style="color: #008000;">:</span>MyUserControl<span style="color: #008000;">&gt;</span>
<span style="color: #008000;">&#91;</span><span style="color: #008000;">...</span><span style="color: #008000;">&#93;</span></pre></div></div><p>Related posts:<ol><li><a
href='http://blog.janjonas.net/2011-06-18/aspnet-membership-provider-changing-user-password-without-knowing-old' rel='bookmark' title='ASP.NET Membership Provider: Changing user password without knowing the old one'>ASP.NET Membership Provider: Changing user password without knowing the old one</a></li><li><a
href='http://blog.janjonas.net/2011-11-26/asp_net-mvc_3-remix-library-add-controller-actions-mixins' rel='bookmark' title='ASP.NET MVC 3: Use re-mix library to add controller actions with mixins'>ASP.NET MVC 3: Use re-mix library to add controller actions with mixins</a></li><li><a
href='http://blog.janjonas.net/2012-01-15/asp_net-mvc_3-remix-library-add-controller-actions-mixins-part2' rel='bookmark' title='ASP.NET MVC 3: Use re-mix library to add controller actions with mixins &#8211; Part 2'>ASP.NET MVC 3: Use re-mix library to add controller actions with mixins &#8211; Part 2</a></li></ol></p>]]></content:encoded> <wfw:commentRss>http://blog.janjonas.net/2012-04-06/asp_net-howto-user-control-library-compile-dll-file/feed</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>IIS 7.5 Application Pools: Understanding default identity &#8220;ApplicationPoolIdentity&#8221;</title><link>http://blog.janjonas.net/2012-04-06/iis_75-application-pool-default-identity-applicationpoolidentity</link> <comments>http://blog.janjonas.net/2012-04-06/iis_75-application-pool-default-identity-applicationpoolidentity#comments</comments> <pubDate>Fri, 06 Apr 2012 13:27:03 +0000</pubDate> <dc:creator>Jan Jonas</dc:creator> <category><![CDATA[Howto]]></category> <category><![CDATA[System administration]]></category> <category><![CDATA[IIS]]></category> <category><![CDATA[Microsoft]]></category> <category><![CDATA[Windows]]></category> <guid
isPermaLink="false">http://blog.janjonas.net/?p=1538</guid> <description><![CDATA[In former versions of IIS the default identity for application pools was &#8220;NetworkService&#8220;. Using this option, the application pool runs under the built-in and low-privileged Windows identity &#8220;NETWORKSERVICE&#8220;. The disadvantage of this (old default) option is that multiple services using the Windows identity &#8220;NETWORKSERVICE&#8221; are not isolated from each other, i.e. services could theoretically read, [...]
Related posts:<ol><li><a
href='http://blog.janjonas.net/2012-02-02/iis_7_5-windows_7-how-to-http-error-401_3-unauthorized' rel='bookmark' title='IIS 7.5 on Windows 7: How to fix &#8220;HTTP Error 401.3 &#8211; Unauthorized&#8221;'>IIS 7.5 on Windows 7: How to fix &#8220;HTTP Error 401.3 &#8211; Unauthorized&#8221;</a></li><li><a
href='http://blog.janjonas.net/2010-11-10/windows_7-service-run-razuna_1_4-automatically' rel='bookmark' title='Windows 7: Install service to run Razuna 1.4 automatically'>Windows 7: Install service to run Razuna 1.4 automatically</a></li><li><a
href='http://blog.janjonas.net/2011-03-05/crashplan_pro-windows-connect-remote-headless-client-linux' rel='bookmark' title='CrashPlan PRO &amp; Windows: How to connect to a remote (headless) CrashPlan PRO client running on Linux'>CrashPlan PRO &#038; Windows: How to connect to a remote (headless) CrashPlan PRO client running on Linux</a></li></ol>]]></description> <content:encoded><![CDATA[<p>In former versions of IIS the default identity for application pools was &#8220;<em>NetworkService</em>&#8220;. Using this option, the application pool runs under the built-in and low-privileged Windows identity &#8220;<em>NETWORKSERVICE</em>&#8220;. The disadvantage of this (old default) option is that multiple services using the Windows identity &#8220;<em>NETWORKSERVICE</em>&#8221; are not isolated from each other, i.e. services could theoretically read, write or execute files of the other services.</p><p>In IIS 7 the concept of application pool identities (&#8220;<em>ApplicationPoolIdentity</em>&#8220;) was introduced and became the default identity for application pools in IIS 7.5. Using this identity Windows runs each application pool under a  automatically created virtual account. Please note, that this virtual account is not listed in Windows User Management Console.</p><p>To grant these virtual accounts permissions to files or directories, you need to add the (virtual) identities to a file&#8217;s or directories Access Control List (ACL). Therefore use the permission tab of the file or folder and select the account as follows:</p><ul><li>Set the location to you local machine</li><li>Set the object&#8217;s name to &#8220;<em>IIS AppPool\&lt;name of your application pool&gt;</em>&#8220;</li></ul><p>Summarized application pool identities allow system administrator to easily isolate multiple application pools from each other without manually managing accounts and passwords.</p><p>Related posts:<ol><li><a
href='http://blog.janjonas.net/2012-02-02/iis_7_5-windows_7-how-to-http-error-401_3-unauthorized' rel='bookmark' title='IIS 7.5 on Windows 7: How to fix &#8220;HTTP Error 401.3 &#8211; Unauthorized&#8221;'>IIS 7.5 on Windows 7: How to fix &#8220;HTTP Error 401.3 &#8211; Unauthorized&#8221;</a></li><li><a
href='http://blog.janjonas.net/2010-11-10/windows_7-service-run-razuna_1_4-automatically' rel='bookmark' title='Windows 7: Install service to run Razuna 1.4 automatically'>Windows 7: Install service to run Razuna 1.4 automatically</a></li><li><a
href='http://blog.janjonas.net/2011-03-05/crashplan_pro-windows-connect-remote-headless-client-linux' rel='bookmark' title='CrashPlan PRO &amp; Windows: How to connect to a remote (headless) CrashPlan PRO client running on Linux'>CrashPlan PRO &#038; Windows: How to connect to a remote (headless) CrashPlan PRO client running on Linux</a></li></ol></p>]]></content:encoded> <wfw:commentRss>http://blog.janjonas.net/2012-04-06/iis_75-application-pool-default-identity-applicationpoolidentity/feed</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>ASP.NET MVC 3 &amp; MongoDB: CRUD operations in NoSQL database using FluentMongo</title><link>http://blog.janjonas.net/2012-04-03/asp_net-mvc_3-mongodb-crud-operation-nosql-database-fluentmongo</link> <comments>http://blog.janjonas.net/2012-04-03/asp_net-mvc_3-mongodb-crud-operation-nosql-database-fluentmongo#comments</comments> <pubDate>Tue, 03 Apr 2012 19:55:12 +0000</pubDate> <dc:creator>Jan Jonas</dc:creator> <category><![CDATA[Howto]]></category> <category><![CDATA[Programming]]></category> <category><![CDATA[.NET]]></category> <category><![CDATA[MongoDB]]></category> <category><![CDATA[MVC]]></category> <category><![CDATA[MVC 3]]></category> <category><![CDATA[NoSQL]]></category> <guid
isPermaLink="false">http://blog.janjonas.net/?p=1525</guid> <description><![CDATA[This blog post shows how to use the open-source NoSQL database MongoDB in an ASP.NET MVC 3 web application. The showcase web application uses FluentMongo that adds LINQ-support for the 10gen MongoDB C# driver. Summarized the application demonstrates how to perform the basic CRUD (create, read, update and delete) database operations. Before running the example [...]
Related posts:<ol><li><a
href='http://blog.janjonas.net/2012-03-16/asp_net-mvc_3-validate-complex-types-object-list-ajax-form-jquery-json-client-side-server-side' rel='bookmark' title='ASP.NET MVC 3: Validate complex Types (Objects &amp; Lists) in Ajax Form using jQuery and JSON on Client Side and Server Side'>ASP.NET MVC 3: Validate complex Types (Objects &#038; Lists) in Ajax Form using jQuery and JSON on Client Side and Server Side</a></li><li><a
href='http://blog.janjonas.net/2011-06-18/aspnet-mvc3-controller-extension-method-render-partial-view-string' rel='bookmark' title='ASP.NET MVC3: Controller extension methods to render a partial view to string'>ASP.NET MVC3: Controller extension methods to render a partial view to string</a></li><li><a
href='http://blog.janjonas.net/2011-07-24/asp_net-mvc_3-ajax-form-jquery-validate-supporting-unobtrusive-client-side-validation-and-server-side-validation' rel='bookmark' title='ASP.NET MVC 3: Ajax Form with jQuery validate supporting (unobtrusive) Client Side Validation and Server Side Validation'>ASP.NET MVC 3: Ajax Form with jQuery validate supporting (unobtrusive) Client Side Validation and Server Side Validation</a></li></ol>]]></description> <content:encoded><![CDATA[<p>This blog post shows how to use the open-source NoSQL database <a
href="http://www.mongodb.org/" target="_blank">MongoDB</a> in an ASP.NET MVC 3 web application. The showcase web application uses <a
href="https://github.com/craiggwilson/fluent-mongo" target="_blank">FluentMongo</a> that adds LINQ-support for the 10gen MongoDB C# driver. Summarized the application demonstrates how to perform the basic CRUD (create, read, update and delete) database operations.</p><p>Before running the example web application, please make sure that a MongoDB server is up and running on your machine (see <a
href="http://www.mongodb.org/display/DOCS/Quickstart+Windows" target="_blank">MongoDB Quickstart for Windows</a>).</p><p>We start with an empty ASP.NET MVC 3 web application and use the NuGet package manager to install the following packages:</p><ul><li>FluentMongo (installs also the dependent MongoDB C# driver)</li><li>MvcContrib (used in this example to easily create HTML grids)</li></ul><p>After including the required NuGet packages we add our User model (<em>Models/User.cs</em>):</p><div
class="wp_syntax"><div
class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> User
<span style="color: #008000;">&#123;</span>
  <span style="color: #008000;">&#91;</span>BsonId<span style="color: #008000;">&#93;</span>
  <span style="color: #0600FF; font-weight: bold;">public</span> ObjectId ObjectId<span style="color: #008000;">;</span>
&nbsp;
  <span style="color: #008000;">&#91;</span>ScaffoldColumn<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span>
  <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">String</span> Id <span style="color: #008000;">&#123;</span>
    get <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">return</span> ObjectId<span style="color: #008000;">.</span><span style="color: #0000FF;">ToString</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
    set <span style="color: #008000;">&#123;</span> ObjectId <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> ObjectId<span style="color: #008000;">&#40;</span>value<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
  <span style="color: #008000;">&#125;</span>
&nbsp;
  <span style="color: #008000;">&#91;</span>DisplayName<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;First Name&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span>
  <span style="color: #008000;">&#91;</span>Required<span style="color: #008000;">&#93;</span>
  <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">String</span> FirstName <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
&nbsp;
  <span style="color: #008000;">&#91;</span>DisplayName<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Last Name&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span>
  <span style="color: #008000;">&#91;</span>Required<span style="color: #008000;">&#93;</span>
  <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">String</span> LastName <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></div></div><p>Since ASP.NET MVC 3 does not support binding MongoDB&#8217;s <em>ObjectId</em> (used by the database to identify the records) the User model contains two id properties:</p><ul><li><em>ObjectId</em>: The (BSON) id used by MongoDB to identify the records in the database</li><li><em>Id</em>: The (string) id used by the ASP.NET MVC 3 application in GET and POST request data to identify the records</li></ul><p>The getter and setter in the <em>Id</em> attribute &#8220;synchronizes&#8221; the string and the BSON value. In a real world project one should solve this problem in a more generic way, e.g. by implementing a custom <a
href="http://msdn.microsoft.com/en-us/library/dd410405.aspx" target="_blank">ModelBinder</a> or by separating database entities from MVC models.</p><p>Next, we implement the <em>HomeController</em> (<em>Controllers/HomeController.cs)</em> as follows:</p><div
class="wp_syntax"><div
class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> HomeController <span style="color: #008000;">:</span> Controller
<span style="color: #008000;">&#123;</span>
  <span style="color: #0600FF; font-weight: bold;">private</span> MongoCollection<span style="color: #008000;">&lt;</span>User<span style="color: #008000;">&gt;</span> _users<span style="color: #008000;">;</span>
&nbsp;
  <span style="color: #0600FF; font-weight: bold;">public</span> HomeController<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
    MongoDatabase database <span style="color: #008000;">=</span> MongoDatabase<span style="color: #008000;">.</span><span style="color: #0000FF;">Create</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;mongodb://localhost:27017/TestMvc3MongoDB&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    _users <span style="color: #008000;">=</span> database<span style="color: #008000;">.</span><span style="color: #0000FF;">GetCollection</span><span style="color: #008000;">&lt;</span>User<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Users&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  <span style="color: #008000;">&#125;</span>
&nbsp;
  <span style="color: #008000;">&#91;</span>HttpGet<span style="color: #008000;">&#93;</span>
  <span style="color: #0600FF; font-weight: bold;">public</span> ActionResult Delete<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">String</span> id<span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
    var user <span style="color: #008000;">=</span> _users<span style="color: #008000;">.</span><span style="color: #0000FF;">AsQueryable</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">FirstOrDefault</span><span style="color: #008000;">&#40;</span>e <span style="color: #008000;">=&gt;</span> e<span style="color: #008000;">.</span><span style="color: #0000FF;">Id</span> <span style="color: #008000;">==</span> id<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>user <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span> _users<span style="color: #008000;">.</span><span style="color: #0000FF;">Remove</span><span style="color: #008000;">&#40;</span>Query<span style="color: #008000;">.</span><span style="color: #0000FF;">EQ</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;_id&quot;</span>, <span style="color: #008000;">new</span> ObjectId<span style="color: #008000;">&#40;</span>id<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #0600FF; font-weight: bold;">return</span> RedirectToAction<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Index&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  <span style="color: #008000;">&#125;</span>
&nbsp;
  <span style="color: #008000;">&#91;</span>HttpGet<span style="color: #008000;">&#93;</span>
  <span style="color: #0600FF; font-weight: bold;">public</span> ActionResult Edit<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">String</span> id<span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
    var user <span style="color: #008000;">=</span> _users<span style="color: #008000;">.</span><span style="color: #0000FF;">AsQueryable</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">FirstOrDefault</span><span style="color: #008000;">&#40;</span>e <span style="color: #008000;">=&gt;</span> e<span style="color: #008000;">.</span><span style="color: #0000FF;">Id</span> <span style="color: #008000;">==</span> id<span style="color: #008000;">&#41;</span> <span style="color: #008000;">??</span> <span style="color: #008000;">new</span> User<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #0600FF; font-weight: bold;">return</span> View<span style="color: #008000;">&#40;</span>user<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  <span style="color: #008000;">&#125;</span>
&nbsp;
  <span style="color: #008000;">&#91;</span>HttpPost<span style="color: #008000;">&#93;</span>
  <span style="color: #0600FF; font-weight: bold;">public</span> ActionResult Edit<span style="color: #008000;">&#40;</span>User user<span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>ModelState<span style="color: #008000;">.</span><span style="color: #0000FF;">IsValid</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
      _users<span style="color: #008000;">.</span><span style="color: #0000FF;">Save</span><span style="color: #008000;">&#40;</span>user<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
      <span style="color: #0600FF; font-weight: bold;">return</span> RedirectToAction<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Index&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
    <span style="color: #0600FF; font-weight: bold;">return</span> View<span style="color: #008000;">&#40;</span>user<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  <span style="color: #008000;">&#125;</span>
&nbsp;
  <span style="color: #0600FF; font-weight: bold;">public</span> ActionResult Index<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">return</span> View<span style="color: #008000;">&#40;</span>_users<span style="color: #008000;">.</span><span style="color: #0000FF;">AsQueryable</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></div></div><p>In a last step we add the view that shows all records (<em>Views/Home/Index.cshtml</em>):</p><div
class="wp_syntax"><div
class="code"><pre class="csahrp" style="font-family:monospace;">@Html.Grid(Model).Columns(column =&gt; {
    column.For(x =&gt; x.Id).Named(&quot;Person ID&quot;);
    column.For(x =&gt; x.FirstName).Named(&quot;First Name&quot;);
    column.For(x =&gt; x.LastName).Named(&quot;Last Name&quot;);
    column.For(x =&gt; Html.ActionLink(&quot;Edit&quot;, &quot;Edit&quot;, new { id = x.Id }));
    column.For(x =&gt; Html.ActionLink(&quot;Delete&quot;, &quot;Delete&quot;, new { id = x.Id }));
})
&nbsp;
@Html.ActionLink(&quot;Create Record&quot;, &quot;Edit&quot;)</pre></div></div><p>and the view that shows the form to edit and create records (<em>Views/Home/Edit.cshtml</em>):</p><div
class="wp_syntax"><div
class="code"><pre class="csahrp" style="font-family:monospace;">@using (Html.BeginForm())
{
    @Html.Hidden(&quot;Id&quot;, Model.Id);
    @Html.EditorForModel(Model)
    &lt;input type=&quot;submit&quot; value=&quot;Submit&quot;/&gt;
}</pre></div></div><p>You can download the Visual Studio 2010 project containing all the source code <a
href="http://blog.janjonas.net/wp-content/uploads/2012/04/vs_2010-MVC3-MongoDB-CrudOperations.zip" target="_blank">here</a>.</p><p>Related posts:<ol><li><a
href='http://blog.janjonas.net/2012-03-16/asp_net-mvc_3-validate-complex-types-object-list-ajax-form-jquery-json-client-side-server-side' rel='bookmark' title='ASP.NET MVC 3: Validate complex Types (Objects &amp; Lists) in Ajax Form using jQuery and JSON on Client Side and Server Side'>ASP.NET MVC 3: Validate complex Types (Objects &#038; Lists) in Ajax Form using jQuery and JSON on Client Side and Server Side</a></li><li><a
href='http://blog.janjonas.net/2011-06-18/aspnet-mvc3-controller-extension-method-render-partial-view-string' rel='bookmark' title='ASP.NET MVC3: Controller extension methods to render a partial view to string'>ASP.NET MVC3: Controller extension methods to render a partial view to string</a></li><li><a
href='http://blog.janjonas.net/2011-07-24/asp_net-mvc_3-ajax-form-jquery-validate-supporting-unobtrusive-client-side-validation-and-server-side-validation' rel='bookmark' title='ASP.NET MVC 3: Ajax Form with jQuery validate supporting (unobtrusive) Client Side Validation and Server Side Validation'>ASP.NET MVC 3: Ajax Form with jQuery validate supporting (unobtrusive) Client Side Validation and Server Side Validation</a></li></ol></p>]]></content:encoded> <wfw:commentRss>http://blog.janjonas.net/2012-04-03/asp_net-mvc_3-mongodb-crud-operation-nosql-database-fluentmongo/feed</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>ASP.NET MVC 3: Validate complex Types (Objects &amp; Lists) in Ajax Form using jQuery and JSON on Client Side and Server Side</title><link>http://blog.janjonas.net/2012-03-16/asp_net-mvc_3-validate-complex-types-object-list-ajax-form-jquery-json-client-side-server-side</link> <comments>http://blog.janjonas.net/2012-03-16/asp_net-mvc_3-validate-complex-types-object-list-ajax-form-jquery-json-client-side-server-side#comments</comments> <pubDate>Fri, 16 Mar 2012 22:57:20 +0000</pubDate> <dc:creator>Jan Jonas</dc:creator> <category><![CDATA[Howto]]></category> <category><![CDATA[Programming]]></category> <category><![CDATA[.NET]]></category> <category><![CDATA[AJAX]]></category> <category><![CDATA[ASP.NET]]></category> <category><![CDATA[jQuery]]></category> <category><![CDATA[MVC]]></category> <category><![CDATA[MVC 3]]></category> <guid
isPermaLink="false">http://blog.janjonas.net/?p=1515</guid> <description><![CDATA[This blog post shows how to validate models containing complex types such as Objects and Lists in ASP.NET MVC 3. We start with the source code described in one of my previous posts &#8220;ASP.NET MVC 3: Using JSON result for jQuery Ajax Forms validation&#8221; (you can download the Visual Studio 2010 project here). Summarized this [...]
Related posts:<ol><li><a
href='http://blog.janjonas.net/2011-07-24/asp_net-mvc_3-ajax-form-jquery-validate-supporting-unobtrusive-client-side-validation-and-server-side-validation' rel='bookmark' title='ASP.NET MVC 3: Ajax Form with jQuery validate supporting (unobtrusive) Client Side Validation and Server Side Validation'>ASP.NET MVC 3: Ajax Form with jQuery validate supporting (unobtrusive) Client Side Validation and Server Side Validation</a></li><li><a
href='http://blog.janjonas.net/2011-08-07/asp_net-mvc_3-jquery-ajax-submit-ajax-form-supporting-unobtrusive-client-side-validation-and-server-side-validation' rel='bookmark' title='ASP.NET MVC 3: Using jQuery .ajax() function to submit Ajax Form supporting (unobtrusive) Client Side Validation and Server Side Validation'>ASP.NET MVC 3: Using jQuery .ajax() function to submit Ajax Form supporting (unobtrusive) Client Side Validation and Server Side Validation</a></li><li><a
href='http://blog.janjonas.net/2011-08-09/asp_net-mvc_3-json-result-jquery-ajax-form-validation' rel='bookmark' title='ASP.NET MVC 3: Using JSON result for jQuery Ajax Forms validation'>ASP.NET MVC 3: Using JSON result for jQuery Ajax Forms validation</a></li></ol>]]></description> <content:encoded><![CDATA[<p>This blog post shows how to validate models containing complex types such as <em>Objects</em> and <em>Lists</em> in ASP.NET MVC 3.</p><p>We start with the source code described in one of my previous posts <a
href="http://blog.janjonas.net/2011-08-09/asp_net-mvc_3-json-result-jquery-ajax-form-validation">&#8220;ASP.NET MVC 3: Using JSON result for jQuery Ajax Forms validation&#8221;</a> (you can download the Visual Studio 2010 project <a
href="http://blog.janjonas.net/wp-content/uploads/2011/08/vs_2010-mvc-ajax-form-jquery-validation-json.zip">here</a>). Summarized this project contains one Ajax form that supports (unobtrusive) client side and server side validation and uses jQuery and JSON to transfer the form data to the server.</p><p>In a first step we modify the properties of the model (<em>Models/ValidationModel.cs</em>) and add some complex types:</p><div
class="wp_syntax"><div
class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> ValidUserNameAttribue <span style="color: #008000;">:</span> ValidationAttribute
<span style="color: #008000;">&#123;</span>
  <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">bool</span> IsValid<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> value<span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #008000;">&#40;</span>value <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span> <span style="color: #008000;">&amp;</span>amp<span style="color: #008000;">;&amp;</span>amp<span style="color: #008000;">;</span> value<span style="color: #008000;">.</span><span style="color: #0000FF;">ToString</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">==</span> <span style="color: #666666;">&quot;Bob&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> User
<span style="color: #008000;">&#123;</span>
  <span style="color: #008000;">&#91;</span>Required<span style="color: #008000;">&#93;</span>
  <span style="color: #008000;">&#91;</span>StringLength<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">8</span>, MinimumLength <span style="color: #008000;">=</span> <span style="color: #FF0000;">3</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span>
  <span style="color: #008000;">&#91;</span>ValidUserNameAttribue<span style="color: #008000;">&#40;</span>ErrorMessage <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;User name != 'Bob'&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span>
  <span style="color: #008000;">&#91;</span>Display<span style="color: #008000;">&#40;</span>Name <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;User name&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span>
  <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">string</span> UserName <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
&nbsp;
  <span style="color: #008000;">&#91;</span>Required<span style="color: #008000;">&#93;</span>
  <span style="color: #008000;">&#91;</span>StringLength<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">8</span>, MinimumLength <span style="color: #008000;">=</span> <span style="color: #FF0000;">3</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span>
  <span style="color: #008000;">&#91;</span>Display<span style="color: #008000;">&#40;</span>Name <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Display name&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span>
  <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">string</span> DisplayName <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> ValidationModel
<span style="color: #008000;">&#123;</span>
  <span style="color: #0600FF; font-weight: bold;">public</span> User User <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
&nbsp;
  <span style="color: #0600FF; font-weight: bold;">public</span> List Users <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></div></div><p>In a second step we modify the form (<em>Views\Home\Partial\_Form.cshtml</em>) to add input element for the new model properties:</p><div
class="wp_syntax"><div
class="code"><pre class="csharp" style="font-family:monospace;">@model MVC3_Ajax_Form_jQuery_Validation<span style="color: #008000;">.</span><span style="color: #0000FF;">Models</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ValidationModel</span>
&nbsp;
@DateTime<span style="color: #008000;">.</span><span style="color: #0000FF;">Now</span><span style="color: #008000;">:</span> <span style="color: #0600FF; font-weight: bold;">Partial</span><span style="color: #008000;">/</span>_Form<span style="color: #008000;">.</span><span style="color: #0000FF;">cshtml</span> rendered
<span style="color: #008000;">&lt;</span>hr<span style="color: #008000;">/&gt;</span>
&nbsp;
@<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008000;">&#40;</span>Html<span style="color: #008000;">.</span><span style="color: #0000FF;">BeginForm</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Form&quot;</span>, <span style="color: #666666;">&quot;Home&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  <span style="color: #008000;">&lt;</span>h1<span style="color: #008000;">&gt;&lt;</span>em<span style="color: #008000;">&gt;</span>User<span style="color: #008000;">&lt;/</span>em<span style="color: #008000;">&gt;</span> <span style="color: #6666cc; font-weight: bold;">object</span><span style="color: #008000;">&lt;/</span>h1<span style="color: #008000;">&gt;</span>
&nbsp;
  <span style="color: #008000;">&lt;</span>p<span style="color: #008000;">&gt;</span>
    @Html<span style="color: #008000;">.</span><span style="color: #0000FF;">LabelFor</span><span style="color: #008000;">&#40;</span>m <span style="color: #008000;">=&gt;</span> m<span style="color: #008000;">.</span><span style="color: #0000FF;">User</span><span style="color: #008000;">.</span><span style="color: #0000FF;">UserName</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">:</span>
    @Html<span style="color: #008000;">.</span><span style="color: #0000FF;">EditorFor</span><span style="color: #008000;">&#40;</span>m <span style="color: #008000;">=&gt;</span> m<span style="color: #008000;">.</span><span style="color: #0000FF;">User</span><span style="color: #008000;">.</span><span style="color: #0000FF;">UserName</span><span style="color: #008000;">&#41;</span>
    @Html<span style="color: #008000;">.</span><span style="color: #0000FF;">ValidationMessageFor</span><span style="color: #008000;">&#40;</span>m <span style="color: #008000;">=&gt;</span> m<span style="color: #008000;">.</span><span style="color: #0000FF;">User</span><span style="color: #008000;">.</span><span style="color: #0000FF;">UserName</span><span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&lt;/</span>p<span style="color: #008000;">&gt;</span>
&nbsp;
  <span style="color: #008000;">&lt;</span>p<span style="color: #008000;">&gt;</span>
    @Html<span style="color: #008000;">.</span><span style="color: #0000FF;">LabelFor</span><span style="color: #008000;">&#40;</span>m <span style="color: #008000;">=&gt;</span> m<span style="color: #008000;">.</span><span style="color: #0000FF;">User</span><span style="color: #008000;">.</span><span style="color: #0000FF;">DisplayName</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">:</span>
    @Html<span style="color: #008000;">.</span><span style="color: #0000FF;">EditorFor</span><span style="color: #008000;">&#40;</span>m <span style="color: #008000;">=&gt;</span> m<span style="color: #008000;">.</span><span style="color: #0000FF;">User</span><span style="color: #008000;">.</span><span style="color: #0000FF;">DisplayName</span><span style="color: #008000;">&#41;</span>
    @Html<span style="color: #008000;">.</span><span style="color: #0000FF;">ValidationMessageFor</span><span style="color: #008000;">&#40;</span>m <span style="color: #008000;">=&gt;</span> m<span style="color: #008000;">.</span><span style="color: #0000FF;">User</span><span style="color: #008000;">.</span><span style="color: #0000FF;">DisplayName</span><span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&lt;/</span>p<span style="color: #008000;">&gt;</span>
&nbsp;
  <span style="color: #008000;">&lt;</span>h1<span style="color: #008000;">&gt;</span>List of <span style="color: #008000;">&lt;</span>em<span style="color: #008000;">&gt;</span>User<span style="color: #008000;">&lt;/</span>em<span style="color: #008000;">&gt;</span> objects<span style="color: #008000;">&lt;/</span>h1<span style="color: #008000;">&gt;</span>
&nbsp;
  <span style="color: #0600FF; font-weight: bold;">for</span> <span style="color: #008000;">&#40;</span>var i <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&lt;=</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">;</span> i<span style="color: #008000;">++</span><span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
    <span style="color: #008000;">&lt;</span>h2<span style="color: #008000;">&gt;</span>User @i<span style="color: #008000;">&lt;/</span>h2<span style="color: #008000;">&gt;</span>
&nbsp;
    <span style="color: #008000;">&lt;</span>p<span style="color: #008000;">&gt;</span>
      @Html<span style="color: #008000;">.</span><span style="color: #0000FF;">LabelFor</span><span style="color: #008000;">&#40;</span>m <span style="color: #008000;">=&gt;</span> m<span style="color: #008000;">.</span><span style="color: #0000FF;">Users</span><span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">UserName</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">:</span>
      @Html<span style="color: #008000;">.</span><span style="color: #0000FF;">EditorFor</span><span style="color: #008000;">&#40;</span>m <span style="color: #008000;">=&gt;</span> m<span style="color: #008000;">.</span><span style="color: #0000FF;">Users</span><span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">UserName</span><span style="color: #008000;">&#41;</span>
      @Html<span style="color: #008000;">.</span><span style="color: #0000FF;">ValidationMessageFor</span><span style="color: #008000;">&#40;</span>m <span style="color: #008000;">=&gt;</span> m<span style="color: #008000;">.</span><span style="color: #0000FF;">Users</span><span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">UserName</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&lt;/</span>p<span style="color: #008000;">&gt;</span>
&nbsp;
    <span style="color: #008000;">&lt;</span>p<span style="color: #008000;">&gt;</span>
      @Html<span style="color: #008000;">.</span><span style="color: #0000FF;">LabelFor</span><span style="color: #008000;">&#40;</span>m <span style="color: #008000;">=&gt;</span> m<span style="color: #008000;">.</span><span style="color: #0000FF;">Users</span><span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">DisplayName</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">:</span>
      @Html<span style="color: #008000;">.</span><span style="color: #0000FF;">EditorFor</span><span style="color: #008000;">&#40;</span>m <span style="color: #008000;">=&gt;</span> m<span style="color: #008000;">.</span><span style="color: #0000FF;">Users</span><span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">DisplayName</span><span style="color: #008000;">&#41;</span>
      @Html<span style="color: #008000;">.</span><span style="color: #0000FF;">ValidationMessageFor</span><span style="color: #008000;">&#40;</span>m <span style="color: #008000;">=&gt;</span> m<span style="color: #008000;">.</span><span style="color: #0000FF;">Users</span><span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">DisplayName</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&lt;/</span>p<span style="color: #008000;">&gt;</span>
  <span style="color: #008000;">&#125;</span>
&nbsp;
  <span style="color: #008000;">&lt;</span>input type<span style="color: #008000;">=</span><span style="color: #666666;">&quot;submit&quot;</span> value<span style="color: #008000;">=</span><span style="color: #666666;">&quot;Submit&quot;</span> <span style="color: #008000;">/&gt;</span>
<span style="color: #008000;">&#125;</span></pre></div></div><p>In a last step we adapt the &#8220;success-view&#8221; (<em>Views\Home\Partial\_Success.cshtml</em>) that is shown after the data have been successfully validated on the server side:</p><div
class="wp_syntax"><div
class="code"><pre class="csharp" style="font-family:monospace;">@model MVC3_Ajax_Form_jQuery_Validation<span style="color: #008000;">.</span><span style="color: #0000FF;">Models</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ValidationModel</span>
&nbsp;
<span style="color: #008000;">&lt;</span>p<span style="color: #008000;">&gt;&lt;</span>strong<span style="color: #008000;">&gt;</span>Model <span style="color: #008000;">is</span> valid <span style="color: #008000;">:</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&lt;/</span>strong<span style="color: #008000;">&gt;&lt;/</span>p<span style="color: #008000;">&gt;</span>
&nbsp;
<span style="color: #008000;">&lt;</span>p<span style="color: #008000;">&gt;</span>
  Model<span style="color: #008000;">.</span><span style="color: #0000FF;">User</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Username</span><span style="color: #008000;">:</span> <span style="color: #666666;">'@Model.User.UserName'</span><span style="color: #008000;">&lt;</span>br <span style="color: #008000;">/&gt;</span>
  Model<span style="color: #008000;">.</span><span style="color: #0000FF;">User</span><span style="color: #008000;">.</span><span style="color: #0000FF;">DisplayName</span><span style="color: #008000;">:</span> <span style="color: #666666;">'@Model.User.DisplayName'</span><span style="color: #008000;">&lt;</span>br <span style="color: #008000;">/&gt;</span>
  Model<span style="color: #008000;">.</span><span style="color: #0000FF;">Users</span><span style="color: #008000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Username</span><span style="color: #008000;">:</span> <span style="color: #666666;">'@Model.Users[0].UserName'</span><span style="color: #008000;">&lt;</span>br <span style="color: #008000;">/&gt;</span>
  Model<span style="color: #008000;">.</span><span style="color: #0000FF;">Users</span><span style="color: #008000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">DisplayName</span><span style="color: #008000;">:</span> <span style="color: #666666;">'@Model.Users[0].DisplayName'</span><span style="color: #008000;">&lt;</span>br <span style="color: #008000;">/&gt;</span>
  Model<span style="color: #008000;">.</span><span style="color: #0000FF;">Users</span><span style="color: #008000;">&#91;</span><span style="color: #FF0000;">1</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Username</span><span style="color: #008000;">:</span> <span style="color: #666666;">'@Model.Users[1].UserName'</span><span style="color: #008000;">&lt;</span>br <span style="color: #008000;">/&gt;</span>
  Model<span style="color: #008000;">.</span><span style="color: #0000FF;">Users</span><span style="color: #008000;">&#91;</span><span style="color: #FF0000;">1</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">DisplayName</span><span style="color: #008000;">:</span> <span style="color: #666666;">'@Model.Users[1].DisplayName'</span>
<span style="color: #008000;">&lt;/</span>p<span style="color: #008000;">&gt;</span></pre></div></div><p>As you can see in the source code above, there is no magic; model binding and validation of complex objects and lists work out of the box in ASP.NET MVC 3.</p><p>You can download the Visual Studio 2010 project containing all the source code <a
href="http://blog.janjonas.net/wp-content/uploads/2012/03/vs_2010-mvc-ajax-form-jquery-validation-json-complex-types.zip">here</a>.</p><p>Related posts:<ol><li><a
href='http://blog.janjonas.net/2011-07-24/asp_net-mvc_3-ajax-form-jquery-validate-supporting-unobtrusive-client-side-validation-and-server-side-validation' rel='bookmark' title='ASP.NET MVC 3: Ajax Form with jQuery validate supporting (unobtrusive) Client Side Validation and Server Side Validation'>ASP.NET MVC 3: Ajax Form with jQuery validate supporting (unobtrusive) Client Side Validation and Server Side Validation</a></li><li><a
href='http://blog.janjonas.net/2011-08-07/asp_net-mvc_3-jquery-ajax-submit-ajax-form-supporting-unobtrusive-client-side-validation-and-server-side-validation' rel='bookmark' title='ASP.NET MVC 3: Using jQuery .ajax() function to submit Ajax Form supporting (unobtrusive) Client Side Validation and Server Side Validation'>ASP.NET MVC 3: Using jQuery .ajax() function to submit Ajax Form supporting (unobtrusive) Client Side Validation and Server Side Validation</a></li><li><a
href='http://blog.janjonas.net/2011-08-09/asp_net-mvc_3-json-result-jquery-ajax-form-validation' rel='bookmark' title='ASP.NET MVC 3: Using JSON result for jQuery Ajax Forms validation'>ASP.NET MVC 3: Using JSON result for jQuery Ajax Forms validation</a></li></ol></p>]]></content:encoded> <wfw:commentRss>http://blog.janjonas.net/2012-03-16/asp_net-mvc_3-validate-complex-types-object-list-ajax-form-jquery-json-client-side-server-side/feed</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Java: Test if String matches wildcard expression</title><link>http://blog.janjonas.net/2012-03-06/java-test-string-match-wildcard-expression</link> <comments>http://blog.janjonas.net/2012-03-06/java-test-string-match-wildcard-expression#comments</comments> <pubDate>Tue, 06 Mar 2012 09:00:17 +0000</pubDate> <dc:creator>Jan Jonas</dc:creator> <category><![CDATA[Howto]]></category> <category><![CDATA[Programming]]></category> <category><![CDATA[Java]]></category> <guid
isPermaLink="false">http://blog.janjonas.net/?p=1505</guid> <description><![CDATA[The following Java method tests if a string matches a wildcard expression (supporting ? for exactly one character or * for an arbitrary number of characters): /** * @param text Text to test * @param pattern (Wildcard) pattern to test * @return True if the text matches the wildcard pattern */ public static boolean match&#40;String [...]
Related posts:<ol><li><a
href='http://blog.janjonas.net/2011-06-18/aspnet-mvc3-controller-extension-method-render-partial-view-string' rel='bookmark' title='ASP.NET MVC3: Controller extension methods to render a partial view to string'>ASP.NET MVC3: Controller extension methods to render a partial view to string</a></li><li><a
href='http://blog.janjonas.net/2011-06-18/aspnet-membership-provider-changing-user-password-without-knowing-old' rel='bookmark' title='ASP.NET Membership Provider: Changing user password without knowing the old one'>ASP.NET Membership Provider: Changing user password without knowing the old one</a></li><li><a
href='http://blog.janjonas.net/2011-01-14/windows-android-sdk-installer-does-not-find-java-development-kit-jdk' rel='bookmark' title='Windows: Android SDK installer does not find Java SE Development Kit (JDK)'>Windows: Android SDK installer does not find Java SE Development Kit (JDK)</a></li></ol>]]></description> <content:encoded><![CDATA[<p>The following Java method tests if a string matches a wildcard expression (supporting <em>?</em> for exactly one character or <em>*</em> for an arbitrary number of characters):</p><div
class="wp_syntax"><div
class="code"><pre class="java" style="font-family:monospace;"><span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * @param text Text to test
 * @param pattern (Wildcard) pattern to test
 * @return True if the text matches the wildcard pattern
 */</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">boolean</span> match<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> text, <span style="color: #003399;">String</span> pattern<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">return</span> text.<span style="color: #006633;">matches</span><span style="color: #009900;">&#40;</span>pattern.<span style="color: #006633;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;?&quot;</span>, <span style="color: #0000ff;">&quot;.?&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;*&quot;</span>, <span style="color: #0000ff;">&quot;.*?&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div><p>Here are some tests for this method:</p><div
class="wp_syntax"><div
class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">Assert</span>.<span style="color: #006633;">assertFalse</span><span style="color: #009900;">&#40;</span>match<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;HELLO WORLD&quot;</span>, <span style="color: #0000ff;">&quot;ELLO&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">Assert</span>.<span style="color: #006633;">assertFalse</span><span style="color: #009900;">&#40;</span>match<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;HELLO WORLD&quot;</span>, <span style="color: #0000ff;">&quot;HELLO&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">Assert</span>.<span style="color: #006633;">assertFalse</span><span style="color: #009900;">&#40;</span>match<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;HELLO WORLD&quot;</span>, <span style="color: #0000ff;">&quot;*HELLO&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">Assert</span>.<span style="color: #006633;">assertFalse</span><span style="color: #009900;">&#40;</span>match<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;HELLO WORLD&quot;</span>, <span style="color: #0000ff;">&quot;HELLO WORLD2&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">Assert</span>.<span style="color: #006633;">assertFalse</span><span style="color: #009900;">&#40;</span>match<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;HELLO WORLD&quot;</span>, <span style="color: #0000ff;">&quot;HELLO WORL&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">Assert</span>.<span style="color: #006633;">assertFalse</span><span style="color: #009900;">&#40;</span>match<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;HELLO WORLD&quot;</span>, <span style="color: #0000ff;">&quot;hello world&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">Assert</span>.<span style="color: #006633;">assertTrue</span><span style="color: #009900;">&#40;</span>match<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;HELLO WORLD&quot;</span>, <span style="color: #0000ff;">&quot;*ELLO*&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">Assert</span>.<span style="color: #006633;">assertTrue</span><span style="color: #009900;">&#40;</span>match<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;HELLO WORLD&quot;</span>, <span style="color: #0000ff;">&quot;HELLO*&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">Assert</span>.<span style="color: #006633;">assertTrue</span><span style="color: #009900;">&#40;</span>match<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;HELLO WORLD&quot;</span>, <span style="color: #0000ff;">&quot;*LLO*&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">Assert</span>.<span style="color: #006633;">assertTrue</span><span style="color: #009900;">&#40;</span>match<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;HELLO WORLD&quot;</span>, <span style="color: #0000ff;">&quot;HELLO WORLD&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div><p>Related posts:<ol><li><a
href='http://blog.janjonas.net/2011-06-18/aspnet-mvc3-controller-extension-method-render-partial-view-string' rel='bookmark' title='ASP.NET MVC3: Controller extension methods to render a partial view to string'>ASP.NET MVC3: Controller extension methods to render a partial view to string</a></li><li><a
href='http://blog.janjonas.net/2011-06-18/aspnet-membership-provider-changing-user-password-without-knowing-old' rel='bookmark' title='ASP.NET Membership Provider: Changing user password without knowing the old one'>ASP.NET Membership Provider: Changing user password without knowing the old one</a></li><li><a
href='http://blog.janjonas.net/2011-01-14/windows-android-sdk-installer-does-not-find-java-development-kit-jdk' rel='bookmark' title='Windows: Android SDK installer does not find Java SE Development Kit (JDK)'>Windows: Android SDK installer does not find Java SE Development Kit (JDK)</a></li></ol></p>]]></content:encoded> <wfw:commentRss>http://blog.janjonas.net/2012-03-06/java-test-string-match-wildcard-expression/feed</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>IIS 7.5 on Windows 7: How to fix &#8220;HTTP Error 401.3 &#8211; Unauthorized&#8221;</title><link>http://blog.janjonas.net/2012-02-02/iis_7_5-windows_7-how-to-http-error-401_3-unauthorized</link> <comments>http://blog.janjonas.net/2012-02-02/iis_7_5-windows_7-how-to-http-error-401_3-unauthorized#comments</comments> <pubDate>Thu, 02 Feb 2012 21:23:19 +0000</pubDate> <dc:creator>Jan Jonas</dc:creator> <category><![CDATA[Howto]]></category> <category><![CDATA[System administration]]></category> <category><![CDATA[HTTP]]></category> <category><![CDATA[IIS]]></category> <category><![CDATA[Windows]]></category> <guid
isPermaLink="false">http://blog.janjonas.net/?p=1493</guid> <description><![CDATA[If you try to run a web application on IIS 7.5 and Windows 7 and you get the following error HTTP Error 401.3 &#8211; Unauthorized You do not have permission to view this directory or page because of the access control list (ACL) configuration or encryption settings for this resource on the Web server. it [...]
Related posts:<ol><li><a
href='http://blog.janjonas.net/2012-04-06/iis_75-application-pool-default-identity-applicationpoolidentity' rel='bookmark' title='IIS 7.5 Application Pools: Understanding default identity &#8220;ApplicationPoolIdentity&#8221;'>IIS 7.5 Application Pools: Understanding default identity &#8220;ApplicationPoolIdentity&#8221;</a></li><li><a
href='http://blog.janjonas.net/2010-08-25/microsoft-crm-4_0-fix-trysetfocusonsubject-error-installing-update-rollup-12' rel='bookmark' title='Microsoft CRM 4.0: Fix &#8220;TrySetFocusOnSubject&#8221; error after installing Update Rollup 12'>Microsoft CRM 4.0: Fix &#8220;TrySetFocusOnSubject&#8221; error after installing Update Rollup 12</a></li><li><a
href='http://blog.janjonas.net/2011-04-13/asp_net-prevent-iis_75_overriding-custom-error-page-iis-default-error-page' rel='bookmark' title='ASP.NET: Prevent IIS 7.5 from overriding custom error pages with IIS default error pages'>ASP.NET: Prevent IIS 7.5 from overriding custom error pages with IIS default error pages</a></li></ol>]]></description> <content:encoded><![CDATA[<p>If you try to run a web application on IIS 7.5 and Windows 7 and you get the following error</p><blockquote><p><strong>HTTP Error 401.3 &#8211; Unauthorized</strong><br
/> You do not have permission to view this directory or page because of the access control list (ACL) configuration or encryption settings for this resource on the Web server.</p></blockquote><p>it is most likely because of missing or wrong NTFS permissions. In detail, the identity that is used by the IIS web-server for &#8220;Anonymous Authentication&#8221; needs read permission on the web application&#8217;s physical folder. By default this identity is set to &#8220;<em>IUSR</em>&#8220;. To solve the HTTP Error 401.3 you could either</p><ul><li>Grant read permissions on the web application&#8217;s physical folder for the <em>IUSR</em> user or</li><li>change the identity that is used for &#8220;Anonymous Authentication&#8221; to a user that has the required read permissions. In order to change the identity use the IIS Manager, select the website, select &#8220;Authentication&#8221; (in section IIS), right click on &#8220;Anonymous Authentication&#8221;, run edit action and define a &#8220;Specific user&#8221;.</li></ul><p>Related posts:<ol><li><a
href='http://blog.janjonas.net/2012-04-06/iis_75-application-pool-default-identity-applicationpoolidentity' rel='bookmark' title='IIS 7.5 Application Pools: Understanding default identity &#8220;ApplicationPoolIdentity&#8221;'>IIS 7.5 Application Pools: Understanding default identity &#8220;ApplicationPoolIdentity&#8221;</a></li><li><a
href='http://blog.janjonas.net/2010-08-25/microsoft-crm-4_0-fix-trysetfocusonsubject-error-installing-update-rollup-12' rel='bookmark' title='Microsoft CRM 4.0: Fix &#8220;TrySetFocusOnSubject&#8221; error after installing Update Rollup 12'>Microsoft CRM 4.0: Fix &#8220;TrySetFocusOnSubject&#8221; error after installing Update Rollup 12</a></li><li><a
href='http://blog.janjonas.net/2011-04-13/asp_net-prevent-iis_75_overriding-custom-error-page-iis-default-error-page' rel='bookmark' title='ASP.NET: Prevent IIS 7.5 from overriding custom error pages with IIS default error pages'>ASP.NET: Prevent IIS 7.5 from overriding custom error pages with IIS default error pages</a></li></ol></p>]]></content:encoded> <wfw:commentRss>http://blog.janjonas.net/2012-02-02/iis_7_5-windows_7-how-to-http-error-401_3-unauthorized/feed</wfw:commentRss> <slash:comments>1</slash:comments> </item> <item><title>ASP.NET: Disable browser and proxy caching for aspx resources</title><link>http://blog.janjonas.net/2012-01-28/asp_net-disable-browser-proxy-caching-aspx-resources</link> <comments>http://blog.janjonas.net/2012-01-28/asp_net-disable-browser-proxy-caching-aspx-resources#comments</comments> <pubDate>Sat, 28 Jan 2012 15:45:50 +0000</pubDate> <dc:creator>Jan Jonas</dc:creator> <category><![CDATA[Howto]]></category> <category><![CDATA[Programming]]></category> <category><![CDATA[.NET]]></category> <category><![CDATA[ASP.NET]]></category> <category><![CDATA[HTTP]]></category> <guid
isPermaLink="false">http://blog.janjonas.net/?p=1482</guid> <description><![CDATA[The following lines of code can be put into a .aspx file to prevent the resource from being cached on clients or proxies: &#60;% Response.Cache.SetCacheability&#40;HttpCacheability.NoCache&#41;; Response.Cache.SetNoStore&#40;&#41;; %&#62; To prevent caching, these lines of code change the header of the server&#8217;s HTTP response by setting the following values: Cache-Control: no-cache, no-store Expires: -1 Pragma: no-cache You [...]
Related posts:<ol><li><a
href='http://blog.janjonas.net/2011-07-13/jquery-disable-browser-cache-all-ajax-requests' rel='bookmark' title='jQuery: Disable (browser) cache for all AJAX requests'>jQuery: Disable (browser) cache for all AJAX requests</a></li><li><a
href='http://blog.janjonas.net/2011-08-21/microsoft-iis-7-enable-client-side-browser-caching-static-content-web-config' rel='bookmark' title='Microsoft IIS 7: Enable Client Side Browser Caching for static Content in Web.config'>Microsoft IIS 7: Enable Client Side Browser Caching for static Content in Web.config</a></li><li><a
href='http://blog.janjonas.net/2012-05-10/isa-server-2006-reverse-web-caching-proxy-object-source-cache-info' rel='bookmark' title='ISA Server 2006 as Reverse Web Caching Proxy: Analyze &#8220;Object source&#8221; and &#8220;Cache Info&#8221; fields'>ISA Server 2006 as Reverse Web Caching Proxy: Analyze &#8220;Object source&#8221; and &#8220;Cache Info&#8221; fields</a></li></ol>]]></description> <content:encoded><![CDATA[<p>The following lines of code can be put into a <em>.aspx</em> file to prevent the resource from being cached on clients or proxies:</p><div
class="wp_syntax"><div
class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">&lt;%</span>
Response<span style="color: #008000;">.</span><span style="color: #0000FF;">Cache</span><span style="color: #008000;">.</span><span style="color: #0000FF;">SetCacheability</span><span style="color: #008000;">&#40;</span>HttpCacheability<span style="color: #008000;">.</span><span style="color: #0000FF;">NoCache</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
Response<span style="color: #008000;">.</span><span style="color: #0000FF;">Cache</span><span style="color: #008000;">.</span><span style="color: #0000FF;">SetNoStore</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">%&gt;</span></pre></div></div><p>To prevent caching, these lines of code change the header of the server&#8217;s HTTP response by setting the following values:</p><ul><li><em>Cache-Control: no-cache, no-store</em></li><li><em>Expires: -1</em></li><li><em>Pragma: no-cache</em></li></ul><p>You can read more about other possible caching options that can be passed to <em>SetCacheability()</em> <a
href="http://msdn.microsoft.com/en-us/library/system.web.httpcacheability%28v=vs.80%29.aspx" target="_blank">here</a>.</p><p>Related posts:<ol><li><a
href='http://blog.janjonas.net/2011-07-13/jquery-disable-browser-cache-all-ajax-requests' rel='bookmark' title='jQuery: Disable (browser) cache for all AJAX requests'>jQuery: Disable (browser) cache for all AJAX requests</a></li><li><a
href='http://blog.janjonas.net/2011-08-21/microsoft-iis-7-enable-client-side-browser-caching-static-content-web-config' rel='bookmark' title='Microsoft IIS 7: Enable Client Side Browser Caching for static Content in Web.config'>Microsoft IIS 7: Enable Client Side Browser Caching for static Content in Web.config</a></li><li><a
href='http://blog.janjonas.net/2012-05-10/isa-server-2006-reverse-web-caching-proxy-object-source-cache-info' rel='bookmark' title='ISA Server 2006 as Reverse Web Caching Proxy: Analyze &#8220;Object source&#8221; and &#8220;Cache Info&#8221; fields'>ISA Server 2006 as Reverse Web Caching Proxy: Analyze &#8220;Object source&#8221; and &#8220;Cache Info&#8221; fields</a></li></ol></p>]]></content:encoded> <wfw:commentRss>http://blog.janjonas.net/2012-01-28/asp_net-disable-browser-proxy-caching-aspx-resources/feed</wfw:commentRss> <slash:comments>0</slash:comments> </item> </channel> </rss>
