<?xml version='1.0' encoding='UTF-8'?><rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/" xmlns:blogger="http://schemas.google.com/blogger/2008" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" version="2.0"><channel><atom:id>tag:blogger.com,1999:blog-1934426700208076473</atom:id><lastBuildDate>Wed, 16 Dec 2020 02:35:37 +0000</lastBuildDate><category>LINQ To SQL</category><category>SqlServer</category><category>MVC</category><category>Asp.net</category><category>Unit Testing</category><category>Custom Attributes</category><category>JavaScript</category><category>Visual Studio</category><category>JScript</category><category>Validation</category><category>Business Layer</category><category>DateTime</category><category>GridView</category><category>MasterPage</category><category>Membership</category><category>Navigation</category><category>Regular Expression</category><category>Steelers</category><category>Attach</category><category>C#</category><category>Cache</category><category>Checkbox</category><category>ContentPage</category><category>Database</category><category>Design Patterns</category><category>DetailsView</category><category>FormView</category><category>LINQDataSource</category><category>RegEx</category><category>SPAN</category><category>Silverlight</category><category>T-SQL Scripts</category><category>TimeStamp</category><category>Visual Source Safe</category><category>Visual Studio 2008</category><category>Agile</category><category>Ajax</category><category>App.Config</category><category>Areas</category><category>Authorization</category><category>Azure</category><category>BUILD2012</category><category>CSV</category><category>ClientScript</category><category>Code First</category><category>Code Smells</category><category>Comma Separated Values</category><category>Compress</category><category>ConnectionString</category><category>Data Access Layer</category><category>DataAnnotations</category><category>Design Smells</category><category>Div</category><category>DropDownList</category><category>EntityFramework</category><category>Find / Replace</category><category>Forms Authentication</category><category>Function</category><category>Generics</category><category>Group By</category><category>Groups</category><category>IE</category><category>Interfaces</category><category>Internal Members</category><category>Internet Explorer</category><category>KSOD</category><category>KVM</category><category>Keys</category><category>Label</category><category>ListView</category><category>Lumia 920</category><category>MSTest</category><category>Menu</category><category>MetadataType</category><category>Microsoft</category><category>ModelBinder</category><category>Object expected</category><category>PMP</category><category>Parse</category><category>Password</category><category>PasswordHash</category><category>Postback</category><category>Primary Key</category><category>Profile</category><category>Remove and Sort</category><category>Repository Pattern</category><category>Roles</category><category>SQL Server Management Studio</category><category>ScriptManager</category><category>Scroll Position</category><category>Security</category><category>SimpleMembership</category><category>Stored Procedure</category><category>StoredProcedure</category><category>Text</category><category>Text File</category><category>Textbox</category><category>UpdatePanel</category><category>VB</category><category>Version</category><category>Vista</category><category>Web.Config</category><category>Windows Phone 8</category><category>Xml</category><category>jquery</category><category>uml</category><category>web interface</category><title>Paul Brown</title><description>Musings and ramblings on .Net, Steelers, and other Stuff.</description><link>http://www.paulgbrown.com/</link><managingEditor>noreply@blogger.com (Paul G Brown)</managingEditor><generator>Blogger</generator><openSearch:totalResults>81</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1934426700208076473.post-7489665259278773630</guid><pubDate>Tue, 14 Mar 2017 16:33:00 +0000</pubDate><atom:updated>2017-03-14T11:33:10.719-05:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">SqlServer</category><category domain="http://www.blogger.com/atom/ns#">T-SQL Scripts</category><title>Find All Characters In A Column</title><description>Here&#39;s an updated way to find all characters in a column. Basically, I loop thru the ASCII readable characters and see if they are present in the column. I did skip A-Z and a-z. If you want it to include A-Z and a-z, just comment out the If statements at the bottom of the loop.&lt;br /&gt;
&lt;br /&gt;
DECLARE @ColumnName varchar(200) = &#39;Text&#39;&lt;br /&gt;
DECLARE @TableName varchar(200) = &#39;Rows&#39;&lt;br /&gt;
DECLARE @SchemaName varchar(200) = &#39;SourceData&#39;&lt;br /&gt;
DECLARE @Sql varchar(max)&lt;br /&gt;
DECLARE @MaxLength int = 126&lt;br /&gt;
DECLARE @Iterator int = 32&lt;br /&gt;
&lt;br /&gt;
CREATE TABLE #AllChars&lt;br /&gt;
(&lt;br /&gt;
&amp;nbsp; &amp;nbsp; ColChar CHAR(1),&lt;br /&gt;
&amp;nbsp; &amp;nbsp; Instances int&lt;br /&gt;
)&lt;br /&gt;
&lt;br /&gt;
WHILE @Iterator &amp;lt; @MaxLength&lt;br /&gt;
BEGIN&lt;br /&gt;
&amp;nbsp; &amp;nbsp; SET @Sql = &#39;INSERT INTO #AllChars (ColChar, Instances) SELECT CHAR(&#39; + CAST(@Iterator as varchar) + &#39;), COUNT(*) FROM &#39; + @SchemaName + &#39;.&#39; + @TableName + &#39; WHERE CHARINDEX(CHAR(&#39; + CAST(@Iterator as varchar) + &#39;), Text) &amp;gt; 0&#39; &lt;br /&gt;
&amp;nbsp; &lt;br /&gt;
&amp;nbsp; &amp;nbsp; EXEC (@Sql)&lt;br /&gt;
&amp;nbsp; &lt;br /&gt;
&amp;nbsp; &amp;nbsp; SET @Iterator = @Iterator + 1&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; -- Skips A-Z&lt;br /&gt;
&amp;nbsp; &amp;nbsp; IF @Iterator = 65&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; SET @Iterator = 91&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; -- Skips a-z&lt;br /&gt;
&amp;nbsp; &amp;nbsp; IF @Iterator = 97&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; SET @Iterator = 123&lt;br /&gt;
END&lt;br /&gt;
&lt;br /&gt;
SELECT *&lt;br /&gt;
FROM #AllChars&lt;br /&gt;
WHERE Instances &amp;gt; 0&lt;br /&gt;
ORDER BY colchar&lt;br /&gt;
&lt;br /&gt;
DROP TABLE #AllChars&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;a href=&quot;http://feeds.feedburner.com/PaulBrown&quot; title=&quot;Subscribe to my feed&quot; rel=&quot;alternate&quot; type=&quot;application/rss+xml&quot;&gt;&lt;img src=&quot;http://www.feedburner.com/fb/images/pub/feed-icon32x32.png&quot; alt=&quot;&quot; style=&quot;border:0&quot;/&gt;&lt;/a&gt;&lt;a href=&quot;http://feeds.feedburner.com/PaulBrown&quot; title=&quot;Subscribe to my feed&quot; rel=&quot;alternate&quot; type=&quot;application/rss+xml&quot;&gt;Subscribe in a reader&lt;/a&gt;&lt;/div&gt;</description><link>http://www.paulgbrown.com/2017/03/find-all-characters-in-column.html</link><author>noreply@blogger.com (Paul G Brown)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1934426700208076473.post-5759050117468650488</guid><pubDate>Sun, 12 Jun 2016 21:27:00 +0000</pubDate><atom:updated>2016-06-12T16:27:42.262-05:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Validation</category><title>Back To Basics - Validating a date</title><description>Recently, a lot of my time has been spent working on systems written by someone else. One of the biggest problems I see in these systems is a lack of basic validation. Limiting the length of strings, requiring values and making sure values fall into the allowed range.&lt;br /&gt;
&lt;br /&gt;
The one that annoys me the most is date validation. Let&#39;s be clear, I&#39;m talking about some basic rules to make insure that a date is not just a valid date but is a reasonable value for the data element.&amp;nbsp;January 1, 1900 is a valid date except if we&#39;re talking about a birth date for living people. The current oldest living person is 116 years old and there aren&#39;t that many people over 100. Ask yourself this question, &quot;Are they going to be in my system?&quot; Probably not, so don&#39;t allow it.&lt;br /&gt;
&lt;br /&gt;
This simple rule will keep a lot date typos out of your system. Remember, dates come in different formats MM/dd/yyyy or dd/MM/yyyy or yyyy/MM/dd. Some users will enter zeros such as 08/02/1991 while others might enter 8/2/91. We can&#39;t eliminate all typos but at least we can get worst ones.&lt;br /&gt;
&lt;br /&gt;
What other rules can we put in place? Here&#39;s the two questions you should be asking about any dates in your system.&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;What is the minimum and maximum range?&lt;/li&gt;
&lt;li&gt;Is the date related to some other date that we can use to validate?&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;
Let&#39;s say we&#39;re developing a tracking system for a health screening company. These are the people that make sure you&#39;re not already dead or dying when you buy life insurance. They need to capture the applicant&#39;s date of birth, date the test was ordered and date the screening was performed. The insurance company only insures people between the date of 21 and 65.&lt;br /&gt;
We can come define some simple rules very quickly.&lt;br /&gt;
&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;Date of birth must be between the current date minus 65 years and the current date minus 21 years.&lt;/li&gt;
&lt;li&gt;The date test was ordered must be between the date of birth and the current date.&lt;/li&gt;
&lt;li&gt;The date of screening must be between the date the test was ordered and the current date.&lt;/li&gt;
&lt;/ol&gt;
&lt;br /&gt;
That&#39;s all it took. I would probably look to limit the range on the date the test was ordered because it seems like these should be entered in a timely manner. Maybe six months or a year.&lt;br /&gt;
So who is responsible for the developing the rules? The project manager? Business analyst? User? The real answer is you, the developer. Why? The short answer is because in the end, it&#39;s your code that is going to be blamed.&lt;br /&gt;
&lt;br /&gt;
The real answer is you&#39;re the professional. When people hire a professional, they are paying to get a someone who is more knowledgeable about the details. They expect someone who is going to think &quot;you cannot have a date of birth in the future in this system.&quot; You know the look you&#39;re going to get when people discover you can enter a birth date of 02/22/2233.&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://www.comicsandmemes.com/wp-content/uploads/whaaa-meme-comment.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://www.comicsandmemes.com/wp-content/uploads/whaaa-meme-comment.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
So if you&#39;re working with a date element take the time to make sure you get the answers for two simple questions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;a href=&quot;http://feeds.feedburner.com/PaulBrown&quot; title=&quot;Subscribe to my feed&quot; rel=&quot;alternate&quot; type=&quot;application/rss+xml&quot;&gt;&lt;img src=&quot;http://www.feedburner.com/fb/images/pub/feed-icon32x32.png&quot; alt=&quot;&quot; style=&quot;border:0&quot;/&gt;&lt;/a&gt;&lt;a href=&quot;http://feeds.feedburner.com/PaulBrown&quot; title=&quot;Subscribe to my feed&quot; rel=&quot;alternate&quot; type=&quot;application/rss+xml&quot;&gt;Subscribe in a reader&lt;/a&gt;&lt;/div&gt;</description><link>http://www.paulgbrown.com/2016/06/back-to-basics-validating-date.html</link><author>noreply@blogger.com (Paul G Brown)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1934426700208076473.post-6084640624706516949</guid><pubDate>Thu, 21 May 2015 02:10:00 +0000</pubDate><atom:updated>2015-05-20T21:10:38.982-05:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Remove and Sort</category><category domain="http://www.blogger.com/atom/ns#">Visual Studio</category><title>VS Removes Usings and Can&#39;t Find Types</title><description>So I was working tonight and ran into a goofy issue with Visual Studio 2013. I had it Remove and Sort Usings for the entire solution. It did but along the way I kept getting a &quot;Your project doesn&#39;t compile...Do you want to continue&quot; message. Figuring it was some small issue with a quick fix, I hit Yes. Doh!! When it got done, I had a bunch of &quot;The type or namespace name...could not be found (are you missing a using directive or assembly reference?)&quot; errors. I also had a bunch of metadata errors but they weren&#39;t the problem.&lt;br /&gt;
&lt;br /&gt;
When I&#39;d add the needed Using, VS would remove it when I&#39;d save and close the file. Wait a minute, I needed that reference and VS should have known that!! If I added the Using and did a Rebuild, it would leave it there and I could close the file. If the file is open it would give me the same error, red squiggles and Remove Usings would take it back out.&lt;br /&gt;
&lt;br /&gt;
There were two projects that had issues, Entities and Infrastructure. Didn&#39;t matter how many times I&#39;d Rebuild these projects. It was only these two projects.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Solution:&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
I opened the folder containing the solution (right-click on the solution and the option is towards the bottom of the menu).&lt;br /&gt;
&lt;br /&gt;
I closed the solution in VS but left VS open.&lt;br /&gt;
&lt;br /&gt;
I went into each project and deleted the Bin and Obj folders.&lt;br /&gt;
&lt;br /&gt;
I re-opened the solution in VS and did a Rebuild on the solution.&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://1.bp.blogspot.com/-ohN-cp6tgQM/VV09jUj5l4I/AAAAAAAADUA/X80QxvdFf30/s1600/success-kid.jpg&quot; imageanchor=&quot;1&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://1.bp.blogspot.com/-ohN-cp6tgQM/VV09jUj5l4I/AAAAAAAADUA/X80QxvdFf30/s200/success-kid.jpg&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;&lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;a href=&quot;http://feeds.feedburner.com/PaulBrown&quot; title=&quot;Subscribe to my feed&quot; rel=&quot;alternate&quot; type=&quot;application/rss+xml&quot;&gt;&lt;img src=&quot;http://www.feedburner.com/fb/images/pub/feed-icon32x32.png&quot; alt=&quot;&quot; style=&quot;border:0&quot;/&gt;&lt;/a&gt;&lt;a href=&quot;http://feeds.feedburner.com/PaulBrown&quot; title=&quot;Subscribe to my feed&quot; rel=&quot;alternate&quot; type=&quot;application/rss+xml&quot;&gt;Subscribe in a reader&lt;/a&gt;&lt;/div&gt;</description><link>http://www.paulgbrown.com/2015/05/vs-removes-usings-and-cant-find-types.html</link><author>noreply@blogger.com (Paul G Brown)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/-ohN-cp6tgQM/VV09jUj5l4I/AAAAAAAADUA/X80QxvdFf30/s72-c/success-kid.jpg" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1934426700208076473.post-4842596561432478174</guid><pubDate>Mon, 25 Feb 2013 19:51:00 +0000</pubDate><atom:updated>2013-02-25T13:51:17.572-06:00</atom:updated><title>JavaScript runtime error: &#39;$&#39; is undefined</title><description>&lt;p&gt;If you’re developing an MVC4 app and run into this error, you probably haven’t placed your scripts in the Script section.&lt;/p&gt; &lt;p&gt;Looking at the _Layout.cshtml file, you’ll see one of the last lines is&lt;/p&gt;&lt;pre class=&quot;csharpcode&quot;&gt;@RenderSection(&lt;span class=&quot;str&quot;&gt;&quot;scripts&quot;&lt;/span&gt;, required: &lt;span class=&quot;kwrd&quot;&gt;false&lt;/span&gt;)&lt;/pre&gt;
&lt;style type=&quot;text/css&quot;&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, &quot;Courier New&quot;, courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;p&gt;which will render a section titled scripts. The following is a sample:&lt;/p&gt;&lt;pre class=&quot;csharpcode&quot;&gt;@section Scripts
{
    &amp;lt;script type=&lt;span class=&quot;str&quot;&gt;&quot;text/javascript&quot;&lt;/span&gt;&amp;gt;
        $(function () {
            alert(&lt;span class=&quot;str&quot;&gt;&quot;JQuery loaded and working!!&quot;&lt;/span&gt;);
        });
    &amp;lt;/script&amp;gt;
}&lt;/pre&gt;
&lt;style type=&quot;text/css&quot;&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, &quot;Courier New&quot;, courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;p&gt;Here’s a link to &lt;a href=&quot;http://weblogs.asp.net/scottgu/archive/2010/12/30/asp-net-mvc-3-layouts-and-sections-with-razor.aspx&quot;&gt;the Gu man’s discussion of sections&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Cost me about 3 hours. Hope it saves you a few!!!&lt;/p&gt;  &lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;a href=&quot;http://feeds.feedburner.com/PaulBrown&quot; title=&quot;Subscribe to my feed&quot; rel=&quot;alternate&quot; type=&quot;application/rss+xml&quot;&gt;&lt;img src=&quot;http://www.feedburner.com/fb/images/pub/feed-icon32x32.png&quot; alt=&quot;&quot; style=&quot;border:0&quot;/&gt;&lt;/a&gt;&lt;a href=&quot;http://feeds.feedburner.com/PaulBrown&quot; title=&quot;Subscribe to my feed&quot; rel=&quot;alternate&quot; type=&quot;application/rss+xml&quot;&gt;Subscribe in a reader&lt;/a&gt;&lt;/div&gt;</description><link>http://www.paulgbrown.com/2013/02/javascript-runtime-error-is-undefined.html</link><author>noreply@blogger.com (Paul G Brown)</author><thr:total>1</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1934426700208076473.post-8154188871722939360</guid><pubDate>Sat, 23 Feb 2013 21:27:00 +0000</pubDate><atom:updated>2013-02-23T15:27:25.926-06:00</atom:updated><title>First NuGet Public Package: States &amp; Provinces</title><description>&lt;p&gt;I recently had to code a drop down for a state field on an entry form. Didn’t take long and not a big pain but I thought, why is there no NuGet package for this. So,,,,&lt;/p&gt; &lt;p&gt;First, states and provinces are generically termed political subregions or geographic subdivisions. There is an &lt;a href=&quot;http://en.wikipedia.org/wiki/ISO_3166&quot;&gt;ISO standard&lt;/a&gt; so we’ll follow that.&lt;/p&gt; &lt;p&gt;First thing we need is a representation of the subregion.&lt;/p&gt;&lt;pre class=&quot;csharpcode&quot;&gt;&lt;span class=&quot;rem&quot;&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;span class=&quot;rem&quot;&gt;/// Represents a political subregion such as a state or province.&lt;/span&gt;
&lt;span class=&quot;rem&quot;&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt; SubRegion
{
    &lt;span class=&quot;rem&quot;&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;rem&quot;&gt;/// Gets or sets the name of the subregion.&lt;/span&gt;
    &lt;span class=&quot;rem&quot;&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; Name { get; set; }

    &lt;span class=&quot;rem&quot;&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;rem&quot;&gt;/// Gets or sets the ISO-3166 code for the subregion.&lt;/span&gt;
    &lt;span class=&quot;rem&quot;&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; IsoCode { get; set; }

    &lt;span class=&quot;rem&quot;&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;rem&quot;&gt;/// Gets or sets the standard abbreviation for the subregion.&lt;/span&gt;
    &lt;span class=&quot;rem&quot;&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;rem&quot;&gt;/// &amp;lt;remarks&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;rem&quot;&gt;/// For the US, this is the USPS 2 character abbreviation.&lt;/span&gt;
    &lt;span class=&quot;rem&quot;&gt;/// &amp;lt;/remarks&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; Abbreviation { get; set; }

    &lt;span class=&quot;rem&quot;&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;rem&quot;&gt;/// Gets or sets an alternative abbreviation that may be used.&lt;/span&gt;
    &lt;span class=&quot;rem&quot;&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;rem&quot;&gt;/// &amp;lt;remarks&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;rem&quot;&gt;/// This is a common local or historical abbreviation.&lt;/span&gt;
    &lt;span class=&quot;rem&quot;&gt;/// &amp;lt;/remarks&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; AlternateAbbreviation { get; set; }
}&lt;/pre&gt;
&lt;style type=&quot;text/css&quot;&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, &quot;Courier New&quot;, courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;p&gt;Now we need a way to identify which countries we can produce. I’m only going to do the US and Canada since that’s all I’ve had to deal with so far. Since we’ll want to support returning more than one country, we’ll add the FlagsAttribute to our enum.&lt;/p&gt;&lt;pre class=&quot;csharpcode&quot;&gt;&lt;span class=&quot;rem&quot;&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;span class=&quot;rem&quot;&gt;/// Represents the countries for whom subregions are available.&lt;/span&gt;
&lt;span class=&quot;rem&quot;&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
[Flags]
&lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;enum&lt;/span&gt; CountrySelection
{
    [Description(&lt;span class=&quot;str&quot;&gt;&quot;Canada&quot;&lt;/span&gt;)]
    Canada = 1,

    [Description(&lt;span class=&quot;str&quot;&gt;&quot;United States&quot;&lt;/span&gt;)]
    UnitedStates = 2
}&lt;/pre&gt;
&lt;style type=&quot;text/css&quot;&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, &quot;Courier New&quot;, courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;p&gt;Now we need a factory to make our lists. The Make method creates an empty list and then adds the desired countries’ subregions. This allows us to return more than just one at a time.&lt;/p&gt;
&lt;p&gt;/// &amp;lt;summary&amp;gt;&lt;br&gt;/// Public member for creating a list of subregions.&lt;br&gt;/// &amp;lt;/summary&amp;gt;&lt;br&gt;/// &amp;lt;param name=&quot;selection&quot;&amp;gt;The country or countries that define the desired subregions.&amp;lt;/param&amp;gt;&lt;br&gt;/// &amp;lt;returns&amp;gt;A generic List of Subregions.&amp;lt;/returns&amp;gt;&lt;br&gt;/// &amp;lt;remarks&amp;gt;&lt;br&gt;/// More that one country may be returned by using the bitwise OR operator.&lt;br&gt;/// &amp;lt;/remarks&amp;gt;&lt;br&gt;public static List&amp;lt;SubRegion&amp;gt; Make(CountrySelection selection)&lt;br&gt;{&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; var results = new List&amp;lt;SubRegion&amp;gt;();&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (selection.HasFlag(CountrySelection.Canada))&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; results.AddRange(MakeCanadianProvinces());&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (selection.HasFlag(CountrySelection.UnitedStates))&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; results.AddRange(MakeUSStates());&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (results.Count == 0)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; throw new System.NotImplementedException(&quot;The country selection has not been implemented.&quot;);&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return results;&lt;br&gt;}&lt;br&gt;&lt;/p&gt;
&lt;p&gt;Then we have a method for each country to keep things neat and organized. Here’s the one for Canada.&lt;/p&gt;
&lt;p&gt;/// &amp;lt;summary&amp;gt;&lt;br&gt;/// Creates the list of Canadian provinces.&lt;br&gt;/// &amp;lt;/summary&amp;gt;&lt;br&gt;/// &amp;lt;returns&amp;gt;A generic List of provinces.&amp;lt;/returns&amp;gt;&lt;br&gt;private static List&amp;lt;SubRegion&amp;gt; MakeCanadianProvinces()&lt;br&gt;{&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; var results = new List&amp;lt;SubRegion&amp;gt;();&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; results.Add(new SubRegion() { Abbreviation = &quot;AB&quot;, Name = &quot;Alberta&quot;, AlternateAbbreviation = &quot;Alta.&quot;, IsoCode = &quot;CA-AB&quot; });&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; results.Add(new SubRegion() { Abbreviation = &quot;BC&quot;, Name = &quot;British Columbia&quot;, AlternateAbbreviation = &quot;B.C.&quot;, IsoCode = &quot;CA-BC&quot; });&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; results.Add(new SubRegion() { Abbreviation = &quot;MB&quot;, Name = &quot;Manitoba&quot;, AlternateAbbreviation = &quot;Man.&quot;, IsoCode = &quot;CA-MB&quot; });&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; results.Add(new SubRegion() { Abbreviation = &quot;NB&quot;, Name = &quot;New Brunswick&quot;, AlternateAbbreviation = &quot;N.B.&quot;, IsoCode = &quot;CA-NB&quot; });&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; results.Add(new SubRegion() { Abbreviation = &quot;NL&quot;, Name = &quot;Newfoundland and Labrador&quot;, AlternateAbbreviation = &quot;Nfld.&quot;, IsoCode = &quot;CA-NL&quot; });&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; results.Add(new SubRegion() { Abbreviation = &quot;NS&quot;, Name = &quot;Nova Scotia&quot;, AlternateAbbreviation = &quot;N.S.&quot;, IsoCode = &quot;CA-NS&quot; });&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; results.Add(new SubRegion() { Abbreviation = &quot;NT&quot;, Name = &quot;Northwest Territories&quot;, AlternateAbbreviation = &quot;N.W.T.&quot;, IsoCode = &quot;CA-NT&quot; });&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; results.Add(new SubRegion() { Abbreviation = &quot;NU&quot;, Name = &quot;Nunavut&quot;, AlternateAbbreviation = &quot;Nun.&quot;, IsoCode = &quot;CA-NU&quot; });&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; results.Add(new SubRegion() { Abbreviation = &quot;ON&quot;, Name = &quot;Ontario&quot;, AlternateAbbreviation = &quot;Ont.&quot;, IsoCode = &quot;CA-ON&quot; });&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; results.Add(new SubRegion() { Abbreviation = &quot;PE&quot;, Name = &quot;Prince Edward Island&quot;, AlternateAbbreviation = &quot;P.E.I.&quot;, IsoCode = &quot;CA-PE&quot; });&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; results.Add(new SubRegion() { Abbreviation = &quot;QC&quot;, Name = &quot;Quebec&quot;, AlternateAbbreviation = &quot;Que.&quot;, IsoCode = &quot;CA-QC&quot; });&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; results.Add(new SubRegion() { Abbreviation = &quot;SK&quot;, Name = &quot;Saskatchewan&quot;, AlternateAbbreviation = &quot;Sask.&quot;, IsoCode = &quot;CA-SK&quot; });&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; results.Add(new SubRegion() { Abbreviation = &quot;YT&quot;, Name = &quot;Yukon&quot;, AlternateAbbreviation = &quot;Yuk.&quot;, IsoCode = &quot;CA-YT&quot; });&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return results;&lt;br&gt;}&lt;br&gt;&lt;/p&gt;
&lt;p&gt;So, if we want to make a list of US states, we simply call our factory.&lt;/p&gt;&lt;pre class=&quot;csharpcode&quot;&gt;var states = Factory.Make(CountrySelection.UnitedStates);&lt;/pre&gt;
&lt;style type=&quot;text/css&quot;&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, &quot;Courier New&quot;, courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;p&gt;Let’s get the US and Canada&lt;/p&gt;&lt;pre class=&quot;csharpcode&quot;&gt;var usAndCanada = Factory.Make(CountrySelection.UnitedStates | CountrySelection.Canada);&lt;/pre&gt;
&lt;style type=&quot;text/css&quot;&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, &quot;Courier New&quot;, courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;p&gt;I’m making this a public project on &lt;a href=&quot;https://github.com/paulgbrown/StatesAndProvinces&quot;&gt;GitHub&lt;/a&gt; so others can add the information for their country. Hope you find it useful.&lt;/p&gt;  &lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;a href=&quot;http://feeds.feedburner.com/PaulBrown&quot; title=&quot;Subscribe to my feed&quot; rel=&quot;alternate&quot; type=&quot;application/rss+xml&quot;&gt;&lt;img src=&quot;http://www.feedburner.com/fb/images/pub/feed-icon32x32.png&quot; alt=&quot;&quot; style=&quot;border:0&quot;/&gt;&lt;/a&gt;&lt;a href=&quot;http://feeds.feedburner.com/PaulBrown&quot; title=&quot;Subscribe to my feed&quot; rel=&quot;alternate&quot; type=&quot;application/rss+xml&quot;&gt;Subscribe in a reader&lt;/a&gt;&lt;/div&gt;</description><link>http://www.paulgbrown.com/2013/02/first-nuget-public-package-states.html</link><author>noreply@blogger.com (Paul G Brown)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1934426700208076473.post-7825710261903308717</guid><pubDate>Fri, 16 Nov 2012 19:53:00 +0000</pubDate><atom:updated>2012-11-16T13:53:23.865-06:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Membership</category><category domain="http://www.blogger.com/atom/ns#">MVC</category><category domain="http://www.blogger.com/atom/ns#">PasswordHash</category><category domain="http://www.blogger.com/atom/ns#">SimpleMembership</category><title>Migrating Legacy Apps to the New SimpleMembership Provider</title><description>&lt;p&gt;&lt;font size=&quot;2&quot;&gt;Asp.Net MVC4 uses the new SimpleMembership provider, changes the table structure and adds a new hashing algorithm. The reasons for the changes can be found in &lt;/font&gt;&lt;a href=&quot;http://weblogs.asp.net/jgalloway/archive/2012/08/29/simplemembership-membership-providers-universal-providers-and-the-new-asp-net-4-5-web-forms-and-asp-net-mvc-4-templates.aspx&quot;&gt;&lt;font size=&quot;2&quot;&gt;this article&lt;/font&gt;&lt;/a&gt;&lt;font size=&quot;2&quot;&gt; by Jon Galloway. This article shows how to migrate your existing apps to the new provider.&lt;/font&gt;  &lt;p&gt;&lt;font size=&quot;2&quot;&gt;I’m assuming that you stored your passwords in the unrecoverable SHA-1 format. If you didn’t, then you’ll have to change a couple of things. All of my apps are done this way so… I’m also assuming that you have created the basic skeleton of the new app and ran it once so the correct tables will be created.&lt;/font&gt;  &lt;p&gt;&lt;font size=&quot;2&quot;&gt;First, we’ll look at the new tables. Previously, we had all of those aspnet_xxxxxx tables. Here’s the new ones.&lt;/font&gt;&lt;/p&gt; &lt;table cellspacing=&quot;0&quot; cellpadding=&quot;2&quot; width=&quot;544&quot; border=&quot;0&quot;&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td valign=&quot;top&quot; width=&quot;200&quot;&gt;UserProfile&lt;/td&gt; &lt;td valign=&quot;top&quot; width=&quot;342&quot;&gt;Contains all of the elements relevant to the user. This is a combination of the aspnet_Users table and the aspnet_Profiles table.&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td valign=&quot;top&quot; width=&quot;200&quot;&gt;webpages_Membership&lt;/td&gt; &lt;td valign=&quot;top&quot; width=&quot;342&quot;&gt;Stores the password info when not using OAuth, Live, Facebook, etc. This table is somewhat of a match to the aspnet_Membership table.&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td valign=&quot;top&quot; width=&quot;200&quot;&gt;webpages_OAuthMembership&lt;/td&gt; &lt;td valign=&quot;top&quot; width=&quot;342&quot;&gt;Stores the provider info when using OAuth, Live, Facebook, etc.&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td valign=&quot;top&quot; width=&quot;200&quot;&gt;webpages_Roles&lt;/td&gt; &lt;td valign=&quot;top&quot; width=&quot;342&quot;&gt;The roles available in the system. Matches the aspnet_Roles table.&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td valign=&quot;top&quot; width=&quot;200&quot;&gt;webpages_UsersInRoles&lt;/td&gt; &lt;td valign=&quot;top&quot; width=&quot;342&quot;&gt;The junction table used to place users in roles. Matches the aspnet_UsersInRoles table.&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;p&gt;Here’s a diagram of the tables.&lt;/p&gt; &lt;p&gt;&lt;a href=&quot;http://lh5.ggpht.com/-RHSHYvvmQUc/UKaZsNIW5dI/AAAAAAAAAJg/LkHdYUeCQ2M/s1600-h/image2.png&quot;&gt;&lt;img title=&quot;image&quot; style=&quot;border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px; border-top-width: 0px&quot; border=&quot;0&quot; alt=&quot;image&quot; src=&quot;http://lh3.ggpht.com/-thRS-R8HdVM/UKaZslr2I0I/AAAAAAAAAJo/uglPwKMui6g/image_thumb.png?imgmax=800&quot; width=&quot;244&quot; height=&quot;139&quot;&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Notice there is no ApplicationId. From reading Jon’s post I’m assuming they decided it was much simpler and probably pretty common to imbed the membership tables in the application database or one specifically for the app.&lt;/p&gt; &lt;h4&gt;Preparation&lt;/h4&gt; &lt;p&gt;In the old membership all of the custom properties in a blob field. SimpleMembership let’s you add columns to the UserProfile table. So do that now. In your app, you’ll also need to modify the UserProfile class in the AccountModels.cs file to have corresponding properties. I have FirstName, LastName and Phone in my example so you’ll see where those get copied.&lt;/p&gt; &lt;p&gt;We also need to add a class. Paste the following into the AccountModels.cs file.&lt;/p&gt;&lt;pre class=&quot;csharpcode&quot;&gt;[Table(&lt;span class=&quot;str&quot;&gt;&quot;webpages_Membership&quot;&lt;/span&gt;)]
&lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt; webpages_Membership
{
    [Key]
    &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;int&lt;/span&gt; UserId { get; set; }

    &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; Nullable&amp;lt;DateTime&amp;gt; CreateDate { get; set; }

    &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; ConfirmationToken { get; set; }

    &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;bool&lt;/span&gt; IsConfirmed { get; set; }

    &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; Nullable&amp;lt;DateTime&amp;gt; LastPasswordFailureDate { get; set; }

    &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;int&lt;/span&gt; PasswordFailuresSinceLastSuccess { get; set; }

    &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; Password { get; set; }

    &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; Nullable&amp;lt;DateTime&amp;gt; PasswordChangedDate { get; set; }

    &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; PasswordSalt { get; set; }

    &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; PasswordVerificationToken { get; set; }

    &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; Nullable&amp;lt;DateTime&amp;gt; PasswordVerificationTokenExpirationDate { get; set; }
}&lt;/pre&gt;
&lt;p&gt;Now modify the UsersContext to look like this.&lt;/p&gt;&lt;pre class=&quot;csharpcode&quot;&gt;&lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt; UsersContext : DbContext
{
    &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; UsersContext()
        : &lt;span class=&quot;kwrd&quot;&gt;base&lt;/span&gt;(&lt;span class=&quot;str&quot;&gt;&quot;DefaultConnection&quot;&lt;/span&gt;)
    {
    }

    &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; DbSet&amp;lt;UserProfile&amp;gt; UserProfiles { get; set; }

    &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; DbSet&amp;lt;webpages_Membership&amp;gt; Memberships { get; set; }
}&lt;/pre&gt;
&lt;style type=&quot;text/css&quot;&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, &quot;Courier New&quot;, courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;p&gt;I’m using “DefaultConnection” as my connection string name. You’ll need to modify that accordingly.&lt;/p&gt;
&lt;p&gt;This &lt;a href=&quot;http://pretzelsteelersfan.blogspot.com/2007/03/get-aspnet-profile-properties-from-sql.html&quot;&gt;blog post&lt;/a&gt; has a UDF that will extract your custom properties from the legacy system. We need to add that. I personally have a database titled Utilities that contains all my functions. You’ll need to create the UDF and place the correct database name in the migration script. Hint: Jay Hilden modified my original and placed a copy in the comments section - use that one!&lt;/p&gt;
&lt;p&gt;While your looking at the old tables, get the ApplicationId of the application users you want to migrate. You’ll need in the copy data step.&lt;/p&gt;
&lt;h4&gt;&lt;/h4&gt;
&lt;h4&gt;Copy Your Data&lt;/h4&gt;
&lt;p&gt;Now that we have everything ready, we need to copy the values from the legacy database to the new database. Open a query window in the new database. In the following script, please LegacyDB with the name of your legacy database. You also need to set the @ApplicationId to the correct value.&lt;/p&gt;
&lt;p&gt;Remember I said I had FirstName, LastName and Phone as custom properties. You’ll need to change those lines in this script to get your custom properties. If you don’t have any custom properties, just cut them out.&lt;/p&gt;
&lt;p&gt;If you want to test this script in you can wrap it in BEGIN TRAN and ROLLBACK. You’ll just get higher identity values on the UserProfile table but you can reseed if necessary.&lt;/p&gt;&lt;pre class=&quot;csharpcode&quot;&gt;&lt;span class=&quot;rem&quot;&gt;-- TODO: Set @ApplicationId to match the correct value from aspnet_Applications&lt;/span&gt;
&lt;span class=&quot;kwrd&quot;&gt;DECLARE&lt;/span&gt; @ApplicationId uniqueidentifier = &lt;span class=&quot;str&quot;&gt;&#39;C9F849A0-68AA-47B0-B51B-4D927A9E52F0&#39;&lt;/span&gt;

&lt;span class=&quot;rem&quot;&gt;-- These are the values we&#39;re&lt;/span&gt;
&lt;span class=&quot;rem&quot;&gt;-- just going to default.&lt;/span&gt;
&lt;span class=&quot;kwrd&quot;&gt;DECLARE&lt;/span&gt; @ConfirmationToken nvarchar(128) = &lt;span class=&quot;kwrd&quot;&gt;null&lt;/span&gt;,
    @IsConfirmed &lt;span class=&quot;kwrd&quot;&gt;bit&lt;/span&gt; = 1,
    @LastPasswordFailureDate datetime = &lt;span class=&quot;kwrd&quot;&gt;null&lt;/span&gt;,
    @PasswordFailuresSinceLastSuccess &lt;span class=&quot;kwrd&quot;&gt;int&lt;/span&gt; = 0,
    @PasswordChangedDate datetime = getdate(),
    @PasswordVerificationToken nvarchar(128) = &lt;span class=&quot;kwrd&quot;&gt;null&lt;/span&gt;,
    @PasswordVerificationTokenExpirationDate datetime = &lt;span class=&quot;kwrd&quot;&gt;null&lt;/span&gt;

/* **************** NOTE ***************
This insert &lt;span class=&quot;kwrd&quot;&gt;statement&lt;/span&gt; needs &lt;span class=&quot;kwrd&quot;&gt;to&lt;/span&gt; be modified &lt;span class=&quot;kwrd&quot;&gt;to&lt;/span&gt; handle
your custom profile properties.
It creates our UserProfile record.
The UserId &lt;span class=&quot;kwrd&quot;&gt;is&lt;/span&gt; the &lt;span class=&quot;kwrd&quot;&gt;primary&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;key&lt;/span&gt; that &lt;span class=&quot;kwrd&quot;&gt;is&lt;/span&gt; used 
throughout &lt;span class=&quot;kwrd&quot;&gt;all&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;of&lt;/span&gt; the other tables &lt;span class=&quot;kwrd&quot;&gt;to&lt;/span&gt;
identify a &lt;span class=&quot;kwrd&quot;&gt;user&lt;/span&gt;.
*/
INSERT &lt;span class=&quot;kwrd&quot;&gt;INTO&lt;/span&gt; UserProfile (UserName, FirstName, LastName, Phone)
    &lt;span class=&quot;kwrd&quot;&gt;SELECT&lt;/span&gt; 
        u.UserName,
        Utilities.dbo.GetProfilePropertyValue(&lt;span class=&quot;str&quot;&gt;&#39;FirstName&#39;&lt;/span&gt;, P.PropertyNames, P.PropertyValuesString), 
        Utilities.dbo.GetProfilePropertyValue(&lt;span class=&quot;str&quot;&gt;&#39;LastName&#39;&lt;/span&gt;, P.PropertyNames, P.PropertyValuesString), 
        Utilities.dbo.GetProfilePropertyValue(&lt;span class=&quot;str&quot;&gt;&#39;Phone&#39;&lt;/span&gt;, P.PropertyNames, P.PropertyValuesString)
    &lt;span class=&quot;kwrd&quot;&gt;FROM&lt;/span&gt; LegacyDb.dbo.aspnet_Users &lt;span class=&quot;kwrd&quot;&gt;AS&lt;/span&gt; U 
    &lt;span class=&quot;kwrd&quot;&gt;INNER&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;JOIN&lt;/span&gt; LegacyDb.dbo.aspnet_Membership &lt;span class=&quot;kwrd&quot;&gt;AS&lt;/span&gt; M &lt;span class=&quot;kwrd&quot;&gt;ON&lt;/span&gt; U.UserId = M.UserId 
        &lt;span class=&quot;kwrd&quot;&gt;AND&lt;/span&gt; U.ApplicationId = M.ApplicationId 
    &lt;span class=&quot;kwrd&quot;&gt;INNER&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;JOIN&lt;/span&gt; LegacyDb.dbo.aspnet_Profile &lt;span class=&quot;kwrd&quot;&gt;AS&lt;/span&gt; P &lt;span class=&quot;kwrd&quot;&gt;ON&lt;/span&gt; U.UserId = P.UserId
/* **************** &lt;span class=&quot;kwrd&quot;&gt;END&lt;/span&gt; NOTE *************** */

/* 
This insert creates the membership record &lt;span class=&quot;kwrd&quot;&gt;and&lt;/span&gt; stores the &lt;span class=&quot;kwrd&quot;&gt;old&lt;/span&gt; password &lt;span class=&quot;kwrd&quot;&gt;and&lt;/span&gt; salt.
*/
INSERT &lt;span class=&quot;kwrd&quot;&gt;INTO&lt;/span&gt; webpages_Membership (UserId, CreateDate, ConfirmationToken, IsConfirmed, LastPasswordFailureDate, PasswordFailuresSinceLastSuccess, Password, PasswordChangedDate, PasswordSalt, PasswordVerificationToken, PasswordVerificationTokenExpirationDate)
    &lt;span class=&quot;kwrd&quot;&gt;SELECT&lt;/span&gt;
        up.UserId, 
        m.CreateDate, 
        @ConfirmationToken, 
        M.IsApproved &lt;span class=&quot;kwrd&quot;&gt;as&lt;/span&gt; IsConfirmed, 
        @LastPasswordFailureDate, 
        @PasswordFailuresSinceLastSuccess, 
        m.Password, 
        @PasswordChangedDate, 
        m.PasswordSalt, 
        @PasswordVerificationToken, 
        @PasswordVerificationTokenExpirationDate 
    &lt;span class=&quot;kwrd&quot;&gt;FROM&lt;/span&gt; LegacyDb.dbo.aspnet_Users &lt;span class=&quot;kwrd&quot;&gt;AS&lt;/span&gt; U 
    &lt;span class=&quot;kwrd&quot;&gt;INNER&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;JOIN&lt;/span&gt; LegacyDb.dbo.aspnet_Membership &lt;span class=&quot;kwrd&quot;&gt;AS&lt;/span&gt; M &lt;span class=&quot;kwrd&quot;&gt;ON&lt;/span&gt; U.UserId = M.UserId 
        &lt;span class=&quot;kwrd&quot;&gt;AND&lt;/span&gt; U.ApplicationId = M.ApplicationId 
    &lt;span class=&quot;kwrd&quot;&gt;INNER&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;JOIN&lt;/span&gt; LegacyDb.dbo.aspnet_Profile &lt;span class=&quot;kwrd&quot;&gt;AS&lt;/span&gt; P &lt;span class=&quot;kwrd&quot;&gt;ON&lt;/span&gt; U.UserId = P.UserId
    &lt;span class=&quot;kwrd&quot;&gt;INNER&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;JOIN&lt;/span&gt; UserProfile up &lt;span class=&quot;kwrd&quot;&gt;on&lt;/span&gt; up.UserName = u.UserName

&lt;span class=&quot;rem&quot;&gt;-- Now we move the roles&lt;/span&gt;
INSERT &lt;span class=&quot;kwrd&quot;&gt;INTO&lt;/span&gt; webpages_Roles (RoleName) 
    &lt;span class=&quot;kwrd&quot;&gt;SELECT&lt;/span&gt; r.RoleName &lt;span class=&quot;kwrd&quot;&gt;FROM&lt;/span&gt; LegacyDb.dbo.aspnet_Roles r &lt;span class=&quot;kwrd&quot;&gt;WHERE&lt;/span&gt; r.ApplicationId = @ApplicationId

&lt;span class=&quot;rem&quot;&gt;-- Get everybody in the correct roles.&lt;/span&gt;
INSERT &lt;span class=&quot;kwrd&quot;&gt;INTO&lt;/span&gt; webpages_UsersInRoles
    &lt;span class=&quot;kwrd&quot;&gt;SELECT&lt;/span&gt; up.UserId, wp_R.RoleId
    &lt;span class=&quot;kwrd&quot;&gt;FROM&lt;/span&gt; LegacyDb.dbo.aspnet_UsersInRoles a_UIR
    &lt;span class=&quot;kwrd&quot;&gt;INNER&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;JOIN&lt;/span&gt; LegacyDb.dbo.aspnet_Roles a_R &lt;span class=&quot;kwrd&quot;&gt;ON&lt;/span&gt; a_UIR.RoleId = a_R.RoleId
    &lt;span class=&quot;kwrd&quot;&gt;INNER&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;JOIN&lt;/span&gt; webpages_Roles wp_R &lt;span class=&quot;kwrd&quot;&gt;ON&lt;/span&gt; a_R.RoleName = wp_R.RoleName
    &lt;span class=&quot;kwrd&quot;&gt;INNER&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;JOIN&lt;/span&gt; LegacyDb.dbo.aspnet_Users a_U &lt;span class=&quot;kwrd&quot;&gt;ON&lt;/span&gt; a_UIR.UserId = a_U.UserId
    &lt;span class=&quot;kwrd&quot;&gt;INNER&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;JOIN&lt;/span&gt; UserProfile up &lt;span class=&quot;kwrd&quot;&gt;ON&lt;/span&gt; a_U.UserName = up.UserName&lt;/pre&gt;
&lt;h4&gt;Making The App Work
&lt;style type=&quot;text/css&quot;&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, &quot;Courier New&quot;, courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;/h4&gt;
&lt;p&gt;You might think you’re ready to go but not yet. The old membership used a different hash to store passwords. This means when your user goes to login, they’ll get rejected because the hashed password values don’t match.&lt;/p&gt;
&lt;p&gt;What we’re going to do is manually validate the password using the old hash and then have SimpleMembership “change” the password so that the correct hash is stored in the tables.&lt;/p&gt;
&lt;p&gt;Here’s the code.&lt;/p&gt;&lt;pre class=&quot;csharpcode&quot;&gt;&lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt; LegacySecurity
{
    &lt;span class=&quot;rem&quot;&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;rem&quot;&gt;/// The user&#39;s profile record.&lt;/span&gt;
    &lt;span class=&quot;rem&quot;&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;kwrd&quot;&gt;private&lt;/span&gt; UserProfile userProfile;

    &lt;span class=&quot;rem&quot;&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;rem&quot;&gt;/// The users membership record.&lt;/span&gt;
    &lt;span class=&quot;rem&quot;&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;kwrd&quot;&gt;private&lt;/span&gt; webpages_Membership membership;

    &lt;span class=&quot;rem&quot;&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;rem&quot;&gt;/// The clear text password.&lt;/span&gt;
    &lt;span class=&quot;rem&quot;&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;kwrd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; clearPassword;

    &lt;span class=&quot;rem&quot;&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;rem&quot;&gt;/// The password after it has been hashed using SHA1.&lt;/span&gt;
    &lt;span class=&quot;rem&quot;&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;kwrd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; sha1HashedPassword;

    &lt;span class=&quot;rem&quot;&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;rem&quot;&gt;/// The user&#39;s user name.&lt;/span&gt;
    &lt;span class=&quot;rem&quot;&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;kwrd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; userName;

    &lt;span class=&quot;rem&quot;&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;rem&quot;&gt;/// Inidcates if the authentication token in the cookie should be persisted beyond the current session.&lt;/span&gt;
    &lt;span class=&quot;rem&quot;&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;kwrd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;bool&lt;/span&gt; persistCookie;

    &lt;span class=&quot;rem&quot;&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;rem&quot;&gt;/// Validates the user against legacy values.&lt;/span&gt;
    &lt;span class=&quot;rem&quot;&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;rem&quot;&gt;/// &amp;lt;param name=&quot;userName&quot;&amp;gt;The user&#39;s UserName.&amp;lt;/param&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;rem&quot;&gt;/// &amp;lt;param name=&quot;password&quot;&amp;gt;The user&#39;s password.&amp;lt;/param&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;rem&quot;&gt;/// &amp;lt;param name=&quot;persistCookie&quot;&amp;gt;Inidcates if the authentication token in the cookie should be persisted beyond the current session.&amp;lt;/param&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;rem&quot;&gt;/// &amp;lt;returns&amp;gt;true if the user is validated and logged in, otherwise false.&amp;lt;/returns&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;bool&lt;/span&gt; Login(&lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; userName, &lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; password, &lt;span class=&quot;kwrd&quot;&gt;bool&lt;/span&gt; persistCookie = &lt;span class=&quot;kwrd&quot;&gt;false&lt;/span&gt;)
    {
        &lt;span class=&quot;kwrd&quot;&gt;this&lt;/span&gt;.userName = userName;
        &lt;span class=&quot;kwrd&quot;&gt;this&lt;/span&gt;.clearPassword = password;
        &lt;span class=&quot;kwrd&quot;&gt;this&lt;/span&gt;.persistCookie = persistCookie;

        &lt;span class=&quot;kwrd&quot;&gt;if&lt;/span&gt; (!GetOriginalValues())
        {
            &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;false&lt;/span&gt;;
        }

        SetHashedPassword();

        &lt;span class=&quot;kwrd&quot;&gt;if&lt;/span&gt; (&lt;span class=&quot;kwrd&quot;&gt;this&lt;/span&gt;.sha1HashedPassword != &lt;span class=&quot;kwrd&quot;&gt;this&lt;/span&gt;.membership.Password)
        {
            &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;false&lt;/span&gt;;
        }

        &lt;span class=&quot;kwrd&quot;&gt;this&lt;/span&gt;.SetPasswordAndLoginUser();

        &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;true&lt;/span&gt;;
    }

    &lt;span class=&quot;rem&quot;&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;rem&quot;&gt;/// Gets the original password values&lt;/span&gt;
    &lt;span class=&quot;rem&quot;&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;kwrd&quot;&gt;protected&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;bool&lt;/span&gt; GetOriginalValues()
    {
        &lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; (var context = &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; Models.UsersContext())
        {
            &lt;span class=&quot;kwrd&quot;&gt;this&lt;/span&gt;.userProfile = context.UserProfiles.Where(x =&amp;gt; x.UserName.ToLower() == userName.ToLower()).SingleOrDefault();

            &lt;span class=&quot;kwrd&quot;&gt;if&lt;/span&gt; (&lt;span class=&quot;kwrd&quot;&gt;this&lt;/span&gt;.userProfile == &lt;span class=&quot;kwrd&quot;&gt;null&lt;/span&gt;)
            {
                &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;false&lt;/span&gt;;
            }

            &lt;span class=&quot;kwrd&quot;&gt;this&lt;/span&gt;.membership = context.Memberships.Where(x =&amp;gt; x.UserId == &lt;span class=&quot;kwrd&quot;&gt;this&lt;/span&gt;.userProfile.UserId).SingleOrDefault();

            &lt;span class=&quot;kwrd&quot;&gt;if&lt;/span&gt; (&lt;span class=&quot;kwrd&quot;&gt;this&lt;/span&gt;.membership == &lt;span class=&quot;kwrd&quot;&gt;null&lt;/span&gt;)
            {
                &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;false&lt;/span&gt;;
            }
            
            &lt;span class=&quot;kwrd&quot;&gt;if&lt;/span&gt; (!&lt;span class=&quot;kwrd&quot;&gt;this&lt;/span&gt;.membership.IsConfirmed)
            {
                &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;false&lt;/span&gt;;
            }
        }

        &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;true&lt;/span&gt;;
    }

    &lt;span class=&quot;rem&quot;&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;rem&quot;&gt;/// Encrypts the password using the SHA1 algorithm.&lt;/span&gt;
    &lt;span class=&quot;rem&quot;&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;rem&quot;&gt;/// &amp;lt;remarks&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;rem&quot;&gt;/// Many thanks to Malcolm Swaine for the hashing code.&lt;/span&gt;
    &lt;span class=&quot;rem&quot;&gt;/// http://www.codeproject.com/Articles/32600/Manually-validating-an-ASP-NET-user-account-with-a&lt;/span&gt;
    &lt;span class=&quot;rem&quot;&gt;/// &amp;lt;/remarks&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;kwrd&quot;&gt;protected&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;void&lt;/span&gt; SetHashedPassword()
    {
        &lt;span class=&quot;kwrd&quot;&gt;byte&lt;/span&gt;[] bIn = Encoding.Unicode.GetBytes(clearPassword);
        &lt;span class=&quot;kwrd&quot;&gt;byte&lt;/span&gt;[] bSalt = Convert.FromBase64String(membership.PasswordSalt);
        &lt;span class=&quot;kwrd&quot;&gt;byte&lt;/span&gt;[] bAll = &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;byte&lt;/span&gt;[bSalt.Length + bIn.Length];
        &lt;span class=&quot;kwrd&quot;&gt;byte&lt;/span&gt;[] bRet = &lt;span class=&quot;kwrd&quot;&gt;null&lt;/span&gt;;
        Buffer.BlockCopy(bSalt, 0, bAll, 0, bSalt.Length);
        Buffer.BlockCopy(bIn, 0, bAll, bSalt.Length, bIn.Length);

        HashAlgorithm s = HashAlgorithm.Create(&lt;span class=&quot;str&quot;&gt;&quot;SHA1&quot;&lt;/span&gt;);
            bRet = s.ComputeHash(bAll);
        &lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; newHash = Convert.ToBase64String(bRet);
            &lt;span class=&quot;kwrd&quot;&gt;this&lt;/span&gt;.sha1HashedPassword = newHash;
    }

    &lt;span class=&quot;rem&quot;&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;rem&quot;&gt;/// Sets the password using the new algorithm and perofrms a login.&lt;/span&gt;
    &lt;span class=&quot;rem&quot;&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;kwrd&quot;&gt;protected&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;void&lt;/span&gt; SetPasswordAndLoginUser()
    {
        var token = WebMatrix.WebData.WebSecurity.GeneratePasswordResetToken(&lt;span class=&quot;kwrd&quot;&gt;this&lt;/span&gt;.userName, 2);
            WebMatrix.WebData.WebSecurity.ResetPassword(token, clearPassword);
            WebMatrix.WebData.WebSecurity.Login(userName, clearPassword, persistCookie);
    }
}&lt;/pre&gt;
&lt;style type=&quot;text/css&quot;&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, &quot;Courier New&quot;, courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;p&gt;Here’s how this works. GetOriginalValues retrieves the original hashed password and salt. SetHashedPassword hashes the password entered by the user. The two hashed strings are compared. If they don’t match, false is returned. &lt;/p&gt;
&lt;p&gt;If they do, then SetPasswordAndLoginUser gets a reset token and then immediately resets the password using SimpleMembership. Now everything is stored correctly. We have to use GeneratePasswordResetToken instead of ChangePassword because even though we know the password, we can’t use it because the hashes won’t match. &lt;/p&gt;
&lt;p&gt;We login the user so that the user doesn’t know anything different happened.&lt;/p&gt;
&lt;h4&gt;Not Quite Done&lt;/h4&gt;
&lt;p&gt;We have one thing left to do. We have to get the system to call our Login method. In the AccountController, go to the Login method and replace it with this.&lt;/p&gt;&lt;pre class=&quot;csharpcode&quot;&gt;[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
&lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; ActionResult Login(LoginModel model, &lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; returnUrl)
{
    &lt;span class=&quot;kwrd&quot;&gt;if&lt;/span&gt; (ModelState.IsValid &amp;amp;&amp;amp; WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe))
    {
        &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; RedirectToLocal(returnUrl);
    }

    &lt;span class=&quot;rem&quot;&gt;// Here we check to see if the user has a legacy password.&lt;/span&gt;
    var legacySecurity = &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; LegacySecurity();
    &lt;span class=&quot;kwrd&quot;&gt;if&lt;/span&gt; (ModelState.IsValid &amp;amp;&amp;amp; legacySecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe))
    {
        &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; RedirectToLocal(returnUrl);
    }

    &lt;span class=&quot;rem&quot;&gt;// If we got this far, something failed, redisplay form&lt;/span&gt;
    ModelState.AddModelError(&lt;span class=&quot;str&quot;&gt;&quot;&quot;&lt;/span&gt;, &lt;span class=&quot;str&quot;&gt;&quot;The user name or password provided is incorrect.&quot;&lt;/span&gt;);
    &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; View(model);
}&lt;/pre&gt;
&lt;style type=&quot;text/css&quot;&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, &quot;Courier New&quot;, courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;p&gt;The nice thing about this code is that when we’re done allowing the old hash, we simply remove the code in the middle and it is exactly as it was.&lt;/p&gt;
&lt;p&gt;What about performance? Once a user is converted to the new hash, they won’t hit the legacy check unless they use the wrong password so there should be minimal impact.&lt;/p&gt;
&lt;p&gt;The thing I like about this is that it keeps the user from knowing anything changed.&lt;/p&gt;
&lt;p&gt;Hope this makes life easier for you.&lt;/p&gt;  &lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;a href=&quot;http://feeds.feedburner.com/PaulBrown&quot; title=&quot;Subscribe to my feed&quot; rel=&quot;alternate&quot; type=&quot;application/rss+xml&quot;&gt;&lt;img src=&quot;http://www.feedburner.com/fb/images/pub/feed-icon32x32.png&quot; alt=&quot;&quot; style=&quot;border:0&quot;/&gt;&lt;/a&gt;&lt;a href=&quot;http://feeds.feedburner.com/PaulBrown&quot; title=&quot;Subscribe to my feed&quot; rel=&quot;alternate&quot; type=&quot;application/rss+xml&quot;&gt;Subscribe in a reader&lt;/a&gt;&lt;/div&gt;</description><link>http://www.paulgbrown.com/2012/11/migrating-legacy-apps-to-new.html</link><author>noreply@blogger.com (Paul G Brown)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh3.ggpht.com/-thRS-R8HdVM/UKaZslr2I0I/AAAAAAAAAJo/uglPwKMui6g/s72-c/image_thumb.png?imgmax=800" height="72" width="72"/><thr:total>26</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1934426700208076473.post-4128434657990587201</guid><pubDate>Thu, 08 Nov 2012 22:23:00 +0000</pubDate><atom:updated>2012-11-09T10:35:54.124-06:00</atom:updated><title>Windows 8 Keyboard Shortcuts</title><description>&lt;p&gt;There are numerous posts on the keyboard shortcuts in Windows 8. I’m not going to regurgitate those. Here are the common things you’ll want to do.&lt;/p&gt; &lt;h4&gt;Shut Your Computer Off, Network / Wi-Fi, Volume, Keyboard &lt;/h4&gt; &lt;p&gt;Press Windows+I which brings up the Settings bar (below left). &lt;/p&gt; &lt;p&gt;&lt;a href=&quot;http://lh3.ggpht.com/-V1f5N-c8hCw/UJww1yF3KwI/AAAAAAAAAIw/95udyGd_YXw/s1600-h/WindowsIScrnShot%25255B3%25255D.png&quot;&gt;&lt;img title=&quot;Windows Settings Bar&quot; style=&quot;border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px&quot; border=&quot;0&quot; alt=&quot;Windows Settings Bar&quot; src=&quot;http://lh5.ggpht.com/-Lkeku9UKHxY/UJww2bX_s8I/AAAAAAAAAI4/CMe9EGChp78/WindowsIScrnShot_thumb%25255B1%25255D.png?imgmax=800&quot; width=&quot;141&quot; height=&quot;129&quot;&gt; &lt;/a&gt;&lt;a href=&quot;http://lh3.ggpht.com/-tH_gcf5GRZc/UJww3MQC7GI/AAAAAAAAAJA/w74CRRbw728/s1600-h/WindowsCScrnShot%25255B2%25255D.png&quot;&gt;&lt;img title=&quot;Windows Charms Bar&quot; style=&quot;border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px&quot; border=&quot;0&quot; alt=&quot;Windows Charms Bar&quot; src=&quot;http://lh6.ggpht.com/-sE3tpkFXgXw/UJww3YxYkKI/AAAAAAAAAJI/iDdY8WMIHOU/WindowsCScrnShot_thumb.png?imgmax=800&quot; width=&quot;40&quot; height=&quot;244&quot;&gt;&lt;/a&gt; &lt;/p&gt; &lt;h4&gt;Search, Change Application Settings, Manage Devices&lt;/h4&gt; &lt;p&gt;Windows+C which brings up the Charms bar (above right). Want to find a song or artist in Music, use&lt;/p&gt; &lt;h4&gt;&lt;/h4&gt; &lt;h4&gt;The rest of the story&lt;/h4&gt; &lt;p&gt;If you want to read about other short-cuts and print a handy-dandy cheat sheet, visit the &lt;a href=&quot;http://blogs.windows.com/windows/b/windowsexperience/archive/2012/03/08/getting-around-in-windows-8.aspx&quot;&gt;Windows Experience Blog&lt;/a&gt;.&lt;/p&gt; &lt;h4&gt;IE 10 &lt;/h4&gt; &lt;p&gt;Want to get the most out of IE10, then How-To Geek’s &lt;a href=&quot;http://www.howtogeek.com/123902/the-best-tips-and-tricks-for-getting-the-most-out-of-internet-explorer-10/&quot;&gt;The Best Tips and Tricks for Getting the Most out of Internet Explorer 10&lt;/a&gt; is exactly what you need. There’s also &lt;a href=&quot;http://www.c-sharpcorner.com/UploadFile/83f858/internet-explorer-10-shortcut-keyboard-in-windows-8/&quot;&gt;Internet Explorer 10 Shortcut Keys In Windows 8&lt;/a&gt; which has some Windows 8 stuff also.&lt;/p&gt;  &lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;a href=&quot;http://feeds.feedburner.com/PaulBrown&quot; title=&quot;Subscribe to my feed&quot; rel=&quot;alternate&quot; type=&quot;application/rss+xml&quot;&gt;&lt;img src=&quot;http://www.feedburner.com/fb/images/pub/feed-icon32x32.png&quot; alt=&quot;&quot; style=&quot;border:0&quot;/&gt;&lt;/a&gt;&lt;a href=&quot;http://feeds.feedburner.com/PaulBrown&quot; title=&quot;Subscribe to my feed&quot; rel=&quot;alternate&quot; type=&quot;application/rss+xml&quot;&gt;Subscribe in a reader&lt;/a&gt;&lt;/div&gt;</description><link>http://www.paulgbrown.com/2012/11/windows-8-keyboard-shortcuts.html</link><author>noreply@blogger.com (Paul G Brown)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh5.ggpht.com/-Lkeku9UKHxY/UJww2bX_s8I/AAAAAAAAAI4/CMe9EGChp78/s72-c/WindowsIScrnShot_thumb%25255B1%25255D.png?imgmax=800" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1934426700208076473.post-920341732988059156</guid><pubDate>Wed, 07 Nov 2012 22:58:00 +0000</pubDate><atom:updated>2012-11-07T16:58:17.735-06:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Azure</category><category domain="http://www.blogger.com/atom/ns#">BUILD2012</category><category domain="http://www.blogger.com/atom/ns#">Lumia 920</category><category domain="http://www.blogger.com/atom/ns#">Microsoft</category><category domain="http://www.blogger.com/atom/ns#">Windows Phone 8</category><title>What A Week!!!!</title><description>&lt;p&gt;I just returned from &lt;a href=&quot;http://aka.ms/build&quot;&gt;BUILD 2012&lt;/a&gt; and I can’t say enough about it. If you’ve never been to a Build or PDC, you haven’t been to a conference. Microsoft pulls out all the stops!!! It is amazing. Of course, the goodies are great but they pale in comparison to the people you meet and what you learn.&lt;/p&gt; &lt;h4&gt;The People&lt;/h4&gt; &lt;p&gt;I met some amazing folks but my Hackathon team is at the top of the list: &lt;a href=&quot;http://www.henriksen.no/&quot;&gt;Glenn Henriksen&lt;/a&gt;, &lt;a href=&quot;http://twitter.com/@lindsve&quot;&gt;Geir-Tore Lindsve&lt;/a&gt;, &lt;a href=&quot;https://www.facebook.com/laura.thompson.714655&quot;&gt;Laura Thompson&lt;/a&gt; and &lt;a href=&quot;http://www.linkedin.com/in/technicaljoe&quot;&gt;Joseph Tu&lt;/a&gt;. Five folks who had never met came together win the Windows Azure category! These folks rock!&lt;/p&gt; &lt;p&gt;I also met some ‘softies who just plain kick tail! Sreekanth Kannepalli was our mentor for the Hackathon and was invaluable in our win. We also got help from Denis Delimarschi. Of course, I can’t forget the Dan Fernandez, the host and moderator. It rocked, Dan!!! Arif Shafique and Theo Yaung are two other folks I met through the days. I’m telling you, Microsoft has some smart cookies!! &lt;/p&gt; &lt;h4&gt;The Goodies&lt;/h4&gt; &lt;p&gt;Each attendee got a Microsoft Surface RT 32GB, a Nokia Lumia 920 and 100GB of SkyDrive storage.&lt;/p&gt; &lt;p&gt;Let’s skip the storage and go straight to the Lumia 920. The pictures are stunning even in low light (see below) and the large screen makes them come to life. It’s fast and Windows Phone 8 just flows. &lt;/p&gt; &lt;p&gt;The Surface RT is not an iPad competitior, it’s an extension of your computing space on a tablet. Working on my Surface is not much different than my desktop aside from form factor. Will I do all my work on it? No, but when I need to be mobile and agile, it’s the tool. Using SkyDrive everything is connected and available. I don’t need to think about where things are stored and what I need to do to make sure they are available. Open a Word or Excel doc, use OneNote, just about anything I need to do, I can do. &lt;/p&gt; &lt;p&gt;So far the only glitch seems to be that I sometimes have to restart to get the touchpad working. So far I haven’t figured out the pattern but I sense there is one. Since I use the screen keyboard most of the time, this is not an issue.&lt;/p&gt; &lt;h4&gt;The Technologies&lt;/h4&gt; &lt;p&gt;&lt;strong&gt;Windows 8&lt;/strong&gt; is different but I really like it. If you are not on a touch device, it takes some getting used to (see post on short-cuts coming soon). If you are on a touch device it takes about five minutes to get going and about two days to get the true hang of it. The Metro UI makes sense in a touch world. All of the gestures feel natural and unforced. The Live Tiles feature is visual candy but nice to have. So far, I’ve been running about a month and it is faster than Win7.&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Windows 8 Phone&lt;/strong&gt; flows. Best way to describe it. Everything makes sense and I don’t spend time looking for things that should be there. Only thing I wish it had is the ability to close an app. I know the OS is supposed to take care of that but it’s not perfect yet.&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Windows&lt;/strong&gt; &lt;strong&gt;Azure&lt;/strong&gt; was my “Doh!” moment. I had really passed on it as a miss by Microsoft because I felt the learning curve and cost were going to be high. Wrong! I attended 1 session by Josh Twist and was up and running in nothing flat. More on this in a later post. Looking at the pricing structure, it seems very affordable.&lt;/p&gt; &lt;p&gt;&lt;strong&gt;JavaScript&lt;/strong&gt; was described by Scott Hanselmann as an operating system. Five minutes into his talk and I agreed although it stills seems wrong somehow. JavaScript was everywhere. It’s used to script in Azure which reduces the learning curve tremendously.&lt;/p&gt; &lt;p&gt;That’s it for the overall. I’ll start posting on using the above soon. &lt;/p&gt;  &lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;a href=&quot;http://feeds.feedburner.com/PaulBrown&quot; title=&quot;Subscribe to my feed&quot; rel=&quot;alternate&quot; type=&quot;application/rss+xml&quot;&gt;&lt;img src=&quot;http://www.feedburner.com/fb/images/pub/feed-icon32x32.png&quot; alt=&quot;&quot; style=&quot;border:0&quot;/&gt;&lt;/a&gt;&lt;a href=&quot;http://feeds.feedburner.com/PaulBrown&quot; title=&quot;Subscribe to my feed&quot; rel=&quot;alternate&quot; type=&quot;application/rss+xml&quot;&gt;Subscribe in a reader&lt;/a&gt;&lt;/div&gt;</description><link>http://www.paulgbrown.com/2012/11/what-week.html</link><author>noreply@blogger.com (Paul G Brown)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1934426700208076473.post-7294590301807838891</guid><pubDate>Mon, 21 Nov 2011 19:10:00 +0000</pubDate><atom:updated>2011-11-21T13:10:59.281-06:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">DataAnnotations</category><category domain="http://www.blogger.com/atom/ns#">RegEx</category><category domain="http://www.blogger.com/atom/ns#">Regular Expression</category><title>Diffference Between RegEx.IsMatch and the RegularExpressionAttribute</title><description>&lt;p&gt;I was working on some code that stores a month as CCYYMM string. Of course I wanted to validate the string with Regex so I had the pattern&lt;/p&gt;  &lt;pre&gt;^20[0-2][0-9](0[1-9])|(1[0-2])$&lt;/pre&gt;

&lt;p&gt;Everything was fine as long as I was using Regex.IsMatch. The problems started when I used the RegularExpressionAttribute. Suddenly, I was getting errors everywhere. I constructed a little test to verify that there was a difference. What I found was that using the same string and pattern, yielded different results.&lt;/p&gt;

&lt;p&gt;Here’s my unit test.&lt;/p&gt;

&lt;pre&gt;[TestMethod]
public void DifferenceBetweenIsMatchAndRegExAttribute()
{
  var pattern = &amp;quot;^20[0-2][0-9](0[1-9])|(1[0-2])$&amp;quot;;
  int cnt = 0;
  var months = new string[]
  {
  &amp;quot;201001&amp;quot;,
  &amp;quot;201002&amp;quot;,
  &amp;quot;201003&amp;quot;,
  &amp;quot;201004&amp;quot;,
  &amp;quot;201005&amp;quot;,
  &amp;quot;201006&amp;quot;,
  &amp;quot;201007&amp;quot;,
  &amp;quot;201008&amp;quot;,
  &amp;quot;201009&amp;quot;,
  &amp;quot;201010&amp;quot;,
  &amp;quot;201011&amp;quot;,
  &amp;quot;201012&amp;quot; };&lt;/pre&gt;

&lt;pre&gt;  var attribute = new RegularExpressionAttribute(pattern);
  bool isMatchOk = false;
  bool isAttrOk = false;
 
  foreach (var month in months)
  {
    isMatchOk = System.Text.RegularExpressions.Regex.IsMatch(month, pattern);
    isAttrOk = attribute.IsValid(month);
 
    if (isMatchOk &amp;amp; isAttrOk)
    { cnt += 1; }
  }
 
  Assert.AreEqual(12, cnt);
}&lt;/pre&gt;

&lt;p&gt;You would expect the number of matches to be 12 but it’s actually 9. Why? Because the attribute is matching only the first half of our pattern. It stops at the pipe (|). To prove this, I flipped the sides of the pipe and got 3. If I add parens around both sides of the logical &lt;em&gt;or &lt;/em&gt;I will get the answer I’m looking for.&lt;/p&gt;

&lt;p&gt;^20[0-2][0-9]((0[1-9])|(1[0-2]))$ &lt;/p&gt;

&lt;p&gt;While it seems logical that the RegularExpressionAttribute would use Regex.IsMatch underneath, it apparently is not the case. I’m betting the reason has to do with JavaScript compatibility. Remember, the attribute must also validate client side.&lt;/p&gt;

&lt;p&gt;Cheers!&lt;/p&gt;  &lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;a href=&quot;http://feeds.feedburner.com/PaulBrown&quot; title=&quot;Subscribe to my feed&quot; rel=&quot;alternate&quot; type=&quot;application/rss+xml&quot;&gt;&lt;img src=&quot;http://www.feedburner.com/fb/images/pub/feed-icon32x32.png&quot; alt=&quot;&quot; style=&quot;border:0&quot;/&gt;&lt;/a&gt;&lt;a href=&quot;http://feeds.feedburner.com/PaulBrown&quot; title=&quot;Subscribe to my feed&quot; rel=&quot;alternate&quot; type=&quot;application/rss+xml&quot;&gt;Subscribe in a reader&lt;/a&gt;&lt;/div&gt;</description><link>http://www.paulgbrown.com/2011/11/i-was-working-on-some-code-that-stores.html</link><author>noreply@blogger.com (Paul G Brown)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1934426700208076473.post-7186894268728895907</guid><pubDate>Tue, 26 Apr 2011 19:05:00 +0000</pubDate><atom:updated>2011-04-26T14:09:59.362-05:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Code First</category><category domain="http://www.blogger.com/atom/ns#">EntityFramework</category><category domain="http://www.blogger.com/atom/ns#">SqlServer</category><title>Updated Code To Get Class Definition From Table Structure</title><description>&lt;p&gt;My previous post on &lt;a href=&quot;http://pretzelsteelersfan.blogspot.com/2010/06/script-to-create-metadatatype-classes.html&quot; target=&quot;_blank&quot;&gt;Script to Create MetadataType classes&lt;/a&gt; was to work with LINQ-To-SQL and partial classes. EF 4.1 introduces Code First which uses POCOs and here is the code to create a class definition from a table’s structure.&lt;/p&gt;  &lt;p&gt;Enjoy.&lt;/p&gt;  &lt;pre class=&quot;brush: sql;&quot;&gt;SET NOCOUNT ON
declare @TableName varchar(256) = &#39;BusinessTypes&#39;
declare @EntityName varchar(256) = &#39;BusinessType&#39;
declare @TableSchema varchar(256) = &#39;dbo&#39;

declare @ColumnName varchar(256)
    , @DataType varchar(256)
    , @NewDataType varchar(256)
    , @MaxLength int
    , @Nullable varchar(5)
    
declare @Lines table (Line varchar(1000))

insert into @Lines select &#39;public class &#39; + @EntityName
insert into @Lines select &#39;{&#39;

declare @DataTypes table (SqlDataType varchar(1000), DataType varchar(1000))

insert into @DataTypes (SqlDataType, DataType) values (&#39;bit&#39;, &#39;bool&#39;)
insert into @DataTypes (SqlDataType, DataType) values (&#39;char&#39;, &#39;string&#39;)
insert into @DataTypes (SqlDataType, DataType) values (&#39;datetime&#39;, &#39;DateTime&#39;)
insert into @DataTypes (SqlDataType, DataType) values (&#39;decimal&#39;, &#39;decimal&#39;)
insert into @DataTypes (SqlDataType, DataType) values (&#39;int&#39;, &#39;int&#39;)
insert into @DataTypes (SqlDataType, DataType) values (&#39;money&#39;, &#39;decimal&#39;)
insert into @DataTypes (SqlDataType, DataType) values (&#39;ntext&#39;, &#39;string&#39;)
insert into @DataTypes (SqlDataType, DataType) values (&#39;nvarchar&#39;, &#39;string&#39;)
insert into @DataTypes (SqlDataType, DataType) values (&#39;smalldatetime&#39;, &#39;DateTime&#39;)
insert into @DataTypes (SqlDataType, DataType) values (&#39;timestamp&#39;, &#39;byte[]&#39;)
insert into @DataTypes (SqlDataType, DataType) values (&#39;uniqueidentifier&#39;, &#39;Guid&#39;)
insert into @DataTypes (SqlDataType, DataType) values (&#39;varchar&#39;, &#39;string&#39;)

declare cols cursor for 
    select COLUMN_NAME, Data_type, CHARACTER_MAXIMUM_LENGTH, IS_NULLABLE
    from INFORMATION_SCHEMA.COLUMNS
    where table_Name = @TableName and table_schema = @Tableschema
    order by ORDINAL_POSITION

open cols

fetch next from cols into  @ColumnName, @DataType, @MaxLength, @Nullable
while @@FETCH_STATUS = 0
begin
    select @NewDataType = DataType from @DataTypes where SqlDataType = @DataType
    
    if @DataType in (&#39;varchar&#39;, &#39;char&#39;) and @Nullable = &#39;NO&#39;
        insert into @Lines select char(9) + &#39;[Required]&#39;
        
    if @DataType in (&#39;varchar&#39;, &#39;char&#39;)
        insert into @Lines select char(9) + &#39;[StringLength(&#39; + CAST(@MaxLength as varchar) + &#39;)]&#39;
    
    insert into @Lines select char(9) + &#39;public &#39; + @NewDataType + &#39; &#39; + @ColumnName + &#39; { get; set; }&#39;
    
    insert into @Lines select char(9) + &#39;&#39;
    
    fetch next from cols into  @ColumnName, @DataType, @MaxLength, @Nullable
end

close cols
deallocate cols
insert into @Lines select &#39;}&#39;

select * FROM @Lines

SET NOCOUNT OFF&lt;/pre&gt;  &lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;a href=&quot;http://feeds.feedburner.com/PaulBrown&quot; title=&quot;Subscribe to my feed&quot; rel=&quot;alternate&quot; type=&quot;application/rss+xml&quot;&gt;&lt;img src=&quot;http://www.feedburner.com/fb/images/pub/feed-icon32x32.png&quot; alt=&quot;&quot; style=&quot;border:0&quot;/&gt;&lt;/a&gt;&lt;a href=&quot;http://feeds.feedburner.com/PaulBrown&quot; title=&quot;Subscribe to my feed&quot; rel=&quot;alternate&quot; type=&quot;application/rss+xml&quot;&gt;Subscribe in a reader&lt;/a&gt;&lt;/div&gt;</description><link>http://www.paulgbrown.com/2011/04/updated-code-to-get-class-definition.html</link><author>noreply@blogger.com (Paul G Brown)</author><thr:total>1</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1934426700208076473.post-2822318034934842384</guid><pubDate>Tue, 01 Mar 2011 15:02:00 +0000</pubDate><atom:updated>2011-03-01T09:02:46.586-06:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">MSTest</category><category domain="http://www.blogger.com/atom/ns#">Unit Testing</category><title>Replacement for ExpectedException in MS Test</title><description>&lt;p&gt;This &lt;a href=&quot;http://stackoverflow.com/questions/1944774/in-mstest-how-can-i-verify-exact-error-message-using-expectedexceptiontypeofa&quot; target=&quot;_blank&quot;&gt;StackOverflow thread&lt;/a&gt; has a great solution for the issue that ExpectedException does not allow you to validate the error message. Look at the response from winSharp93 and the ExceptionAssert class. This is a much cleaner method and also shows some great ways to use generics.&lt;/p&gt;  &lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;a href=&quot;http://feeds.feedburner.com/PaulBrown&quot; title=&quot;Subscribe to my feed&quot; rel=&quot;alternate&quot; type=&quot;application/rss+xml&quot;&gt;&lt;img src=&quot;http://www.feedburner.com/fb/images/pub/feed-icon32x32.png&quot; alt=&quot;&quot; style=&quot;border:0&quot;/&gt;&lt;/a&gt;&lt;a href=&quot;http://feeds.feedburner.com/PaulBrown&quot; title=&quot;Subscribe to my feed&quot; rel=&quot;alternate&quot; type=&quot;application/rss+xml&quot;&gt;Subscribe in a reader&lt;/a&gt;&lt;/div&gt;</description><link>http://www.paulgbrown.com/2011/03/replacement-for-expectedexception-in-ms.html</link><author>noreply@blogger.com (Paul G Brown)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1934426700208076473.post-2560972825612254297</guid><pubDate>Fri, 18 Feb 2011 16:50:00 +0000</pubDate><atom:updated>2011-02-18T10:51:12.361-06:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">SqlServer</category><category domain="http://www.blogger.com/atom/ns#">uml</category><title>Script To Grab Column Names As UML Properties</title><description>&lt;p&gt;I was cooking up some UML diagrams for an existing DB and wanted to get all of the properties. It lists the table, column name in UML markup format and then the data type. The data type column is there so that all I have to do is order it by the second column and I’ll get all of the nulls so I can see if I’m getting a data type that I haven’t handled. The data type conversion is by no means complete but it’s a good start.&lt;/p&gt;&lt;p&gt;Enjoy!&lt;/p&gt;&lt;pre class=&quot;brush: sql;&quot;&gt;select table_name, &#39;+ &#39; + column_name + &#39; : &#39; +
    CASE WHEN DATA_TYPE in (&#39;ntext&#39;, &#39;nvarchar&#39;, &#39;varchar&#39;, &#39;char&#39;) then &#39;string&#39;
        WHEN DATA_TYPE = &#39;bit&#39; then &#39;bool&#39;
        WHEN DATA_TYPE = &#39;int&#39; then &#39;int&#39;
        WHEN DATA_TYPE = &#39;timestamp&#39; then &#39;timestamp&#39;
        WHEN DATA_TYPE = &#39;uniqueidentifier&#39; then &#39;Guid&#39;
        WHEN DATA_TYPE = &#39;money&#39; then &#39;decimal&#39;
        WHEN DATA_TYPE in (&#39;smalldatetime&#39;, &#39;datetime&#39;) then &#39;datetime&#39;
        END,
    DATA_TYPE
from INFORMATION_SCHEMA.COLUMNS
where TABLE_NAME not like &#39;%aspnet%&#39;
    and TABLE_NAME &amp;lt;&amp;gt; &#39;sysdiagrams&#39;
order by 1, 2&lt;/pre&gt;&lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;a href=&quot;http://feeds.feedburner.com/PaulBrown&quot; title=&quot;Subscribe to my feed&quot; rel=&quot;alternate&quot; type=&quot;application/rss+xml&quot;&gt;&lt;img src=&quot;http://www.feedburner.com/fb/images/pub/feed-icon32x32.png&quot; alt=&quot;&quot; style=&quot;border:0&quot;/&gt;&lt;/a&gt;&lt;a href=&quot;http://feeds.feedburner.com/PaulBrown&quot; title=&quot;Subscribe to my feed&quot; rel=&quot;alternate&quot; type=&quot;application/rss+xml&quot;&gt;Subscribe in a reader&lt;/a&gt;&lt;/div&gt;</description><link>http://www.paulgbrown.com/2011/02/script-to-grab-column-names-as-uml.html</link><author>noreply@blogger.com (Paul G Brown)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1934426700208076473.post-5746289781715370085</guid><pubDate>Mon, 10 Jan 2011 15:14:00 +0000</pubDate><atom:updated>2011-01-10T09:14:03.494-06:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Database</category><category domain="http://www.blogger.com/atom/ns#">Function</category><category domain="http://www.blogger.com/atom/ns#">SqlServer</category><category domain="http://www.blogger.com/atom/ns#">Stored Procedure</category><category domain="http://www.blogger.com/atom/ns#">StoredProcedure</category><title>SQL To Find String In Procedure/Function</title><description>&lt;p&gt;I do a lot of work updating legacy systems. Almost every system needs the column names updated since the names are usually short and not very descriptive. Here’s a command for finding all store procedures/functions that use a specified column.&lt;/p&gt;  &lt;pre class=&quot;brush: sql;&quot;&gt;select s.name, a.name FROM sys.sql_modules m
inner join sys.all_objects a on m.object_id = a.object_id
inner join sys.schemas s on a.schema_id = s.schema_id
where m.definition like &#39;%MyColumnName%&#39;&lt;/pre&gt;

&lt;p&gt;INFORMATION_SCHEMA.ROUTINES is unreliable because it is limited to the first 4000 characters.&lt;/p&gt;

&lt;p&gt;Enjoy!!&lt;/p&gt;  &lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;a href=&quot;http://feeds.feedburner.com/PaulBrown&quot; title=&quot;Subscribe to my feed&quot; rel=&quot;alternate&quot; type=&quot;application/rss+xml&quot;&gt;&lt;img src=&quot;http://www.feedburner.com/fb/images/pub/feed-icon32x32.png&quot; alt=&quot;&quot; style=&quot;border:0&quot;/&gt;&lt;/a&gt;&lt;a href=&quot;http://feeds.feedburner.com/PaulBrown&quot; title=&quot;Subscribe to my feed&quot; rel=&quot;alternate&quot; type=&quot;application/rss+xml&quot;&gt;Subscribe in a reader&lt;/a&gt;&lt;/div&gt;</description><link>http://www.paulgbrown.com/2011/01/sql-to-find-string-in-procedurefunction.html</link><author>noreply@blogger.com (Paul G Brown)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1934426700208076473.post-4931359304570398410</guid><pubDate>Mon, 03 Jan 2011 15:49:00 +0000</pubDate><atom:updated>2011-01-03T09:49:22.611-06:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">SqlServer</category><category domain="http://www.blogger.com/atom/ns#">Xml</category><title>Read XML File Into SQL Server</title><description>&lt;p&gt;Wayne Sheffield has a nice article on reading XML files into sql. &lt;a href=&quot;http://www.sqlservercentral.com/articles/XML/71659/&quot; target=&quot;_blank&quot;&gt;You can find it here.&lt;/a&gt;&lt;/p&gt;  &lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;a href=&quot;http://feeds.feedburner.com/PaulBrown&quot; title=&quot;Subscribe to my feed&quot; rel=&quot;alternate&quot; type=&quot;application/rss+xml&quot;&gt;&lt;img src=&quot;http://www.feedburner.com/fb/images/pub/feed-icon32x32.png&quot; alt=&quot;&quot; style=&quot;border:0&quot;/&gt;&lt;/a&gt;&lt;a href=&quot;http://feeds.feedburner.com/PaulBrown&quot; title=&quot;Subscribe to my feed&quot; rel=&quot;alternate&quot; type=&quot;application/rss+xml&quot;&gt;Subscribe in a reader&lt;/a&gt;&lt;/div&gt;</description><link>http://www.paulgbrown.com/2011/01/read-xml-file-into-sql-server.html</link><author>noreply@blogger.com (Paul G Brown)</author><thr:total>1</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1934426700208076473.post-6820534086158310202</guid><pubDate>Thu, 28 Oct 2010 15:08:00 +0000</pubDate><atom:updated>2010-10-28T10:08:21.688-05:00</atom:updated><title>User Story Screen</title><description>&lt;p&gt;The user story screen is the starting point for all work. It tells a story from the user perspective that we can use to determine what work needs to be done. This story should be short so that the work can be done in a couple of days. More complicated stories should be broken up into smaller stories so the work can be broken into pieces. My rule of thumb is if the story is takes more than a paragraph or so, you need to break it up.&lt;/p&gt;  &lt;p&gt;Here’s the User Story screen from VS.&lt;/p&gt;  &lt;p&gt;&lt;a href=&quot;http://lh3.ggpht.com/_6SIaqZS_bz4/TMmR4pBjgJI/AAAAAAAAAG0/7BoFobayBiE/s1600-h/User%20Story%5B2%5D.png&quot;&gt;&lt;img style=&quot;background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px&quot; title=&quot;User Story&quot; border=&quot;0&quot; alt=&quot;User Story&quot; src=&quot;http://lh4.ggpht.com/_6SIaqZS_bz4/TMmR5BiWBvI/AAAAAAAAAG4/UweyGVgt1nc/User%20Story_thumb.png?imgmax=800&quot; width=&quot;244&quot; height=&quot;162&quot; /&gt;&lt;/a&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Title&lt;/strong&gt; – A one sentence description of the story.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Assigned&lt;/strong&gt; &lt;strong&gt;To&lt;/strong&gt; – The single individual responsible for the story.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;State&lt;/strong&gt; – Indicates the current state of the story.&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Active – The story is currently being worked on or waiting to be worked on.&lt;/li&gt;    &lt;li&gt;Closed – The story was closed without being resolved.&lt;/li&gt;    &lt;li&gt;Resolved – The story was completed and implemented.&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;strong&gt;Reason&lt;/strong&gt; – The reason the item is in the current state. Matching states are in parenthesis.&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;New – A new story (Active).&lt;/li&gt;    &lt;li&gt;Abandoned – The story was no longer relevant (Closed).&amp;#160; &lt;/li&gt;    &lt;li&gt;Out Of Scope – The story does not fall within the scope of the current project (Closed).&lt;/li&gt;    &lt;li&gt;Rejected – The story was not desired by management, too complex or violates system integrity (Closed).&lt;/li&gt;    &lt;li&gt;Code complete and unit tests pass – Work has been completed and all unit tests pass (Resolved).&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;strong&gt;Area&lt;/strong&gt; – The functional area of the application such as clients, services, etc.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Iteration&lt;/strong&gt; – The iteration of the system where the task will be worked on. This may correspond to sprints but it could be version number based. &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Stack&lt;/strong&gt; &lt;strong&gt;Rank&lt;/strong&gt; – The relative importance of the item to the product owner(s).&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;System/process &lt;b&gt;&lt;u&gt;must&lt;/u&gt;&lt;/b&gt; support this user story / functionality&lt;/li&gt;    &lt;li&gt;System/process &lt;b&gt;&lt;u&gt;should&lt;/u&gt;&lt;/b&gt; support this user story / functionality&lt;/li&gt;    &lt;li&gt;System/process &lt;b&gt;&lt;u&gt;could&lt;/u&gt;&lt;/b&gt; support this user story / functionality&lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;&lt;strong&gt;Story&lt;/strong&gt; &lt;strong&gt;Points&lt;/strong&gt; – An indicator of the complexity of the user story. This value allows for comparison between stories based on an abstract value rather than time (which is not the same between developers).&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Risk&lt;/strong&gt; – The level of risk to the project if the item is not completed.&lt;/p&gt;  &lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;a href=&quot;http://feeds.feedburner.com/PaulBrown&quot; title=&quot;Subscribe to my feed&quot; rel=&quot;alternate&quot; type=&quot;application/rss+xml&quot;&gt;&lt;img src=&quot;http://www.feedburner.com/fb/images/pub/feed-icon32x32.png&quot; alt=&quot;&quot; style=&quot;border:0&quot;/&gt;&lt;/a&gt;&lt;a href=&quot;http://feeds.feedburner.com/PaulBrown&quot; title=&quot;Subscribe to my feed&quot; rel=&quot;alternate&quot; type=&quot;application/rss+xml&quot;&gt;Subscribe in a reader&lt;/a&gt;&lt;/div&gt;</description><link>http://www.paulgbrown.com/2010/10/user-story-screen.html</link><author>noreply@blogger.com (Paul G Brown)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh4.ggpht.com/_6SIaqZS_bz4/TMmR5BiWBvI/AAAAAAAAAG4/UweyGVgt1nc/s72-c/User%20Story_thumb.png?imgmax=800" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1934426700208076473.post-2907265348154252926</guid><pubDate>Thu, 28 Oct 2010 14:34:00 +0000</pubDate><atom:updated>2010-10-28T10:10:02.262-05:00</atom:updated><title>A Simple Man’s Guide To Using VS &amp; TFS 2010</title><description>&lt;p&gt;One of the areas I personally struggle with is planning and organizing. I’m a doer. Git-r-dun! I can see a task and wiz through coding it. As long as I’m the only developer, this works great. When you’re the team lead, it’s not a good thing. What ends up happening is that everything is in your head. The team doesn’t know what to work on and the users don’t know the status of the project. &lt;/p&gt;  &lt;p&gt;Want to know if you’re in this category? Take a day off and see what happens! If you come back and find that things have gone haywire, welcome to the club. &lt;/p&gt;  &lt;p&gt;So what’s the solution? For me, learning Agile and Scrum basics and using VS/TFS 2010 to keep track of stuff. For the next several posts, I ‘m going to document how we’re going to use VS/TFS 2010. If you’ve done it differently, please let me know. I’ll update this post as the master to keep track of everything together.&lt;/p&gt;  &lt;p&gt;The first step will be to create a user story for each discrete activity. Then we’ll write the test cases that insure things are working correctly. Finally, we’ll create the tasks for the actual coding. The following links cover each of the items in VS/TFS 2010 and how we’ll be using them.&lt;/p&gt;  &lt;p&gt;&lt;a href=&quot;http://pretzelsteelersfan.blogspot.com/2010/10/user-story-screen.html&quot;&gt;User Story&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Test Case&lt;/p&gt;  &lt;p&gt;Task&lt;/p&gt;  &lt;p&gt;Bug&lt;/p&gt;  &lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;a href=&quot;http://feeds.feedburner.com/PaulBrown&quot; title=&quot;Subscribe to my feed&quot; rel=&quot;alternate&quot; type=&quot;application/rss+xml&quot;&gt;&lt;img src=&quot;http://www.feedburner.com/fb/images/pub/feed-icon32x32.png&quot; alt=&quot;&quot; style=&quot;border:0&quot;/&gt;&lt;/a&gt;&lt;a href=&quot;http://feeds.feedburner.com/PaulBrown&quot; title=&quot;Subscribe to my feed&quot; rel=&quot;alternate&quot; type=&quot;application/rss+xml&quot;&gt;Subscribe in a reader&lt;/a&gt;&lt;/div&gt;</description><link>http://www.paulgbrown.com/2010/10/simple-mans-guide-to-using-vs-tfs-2010.html</link><author>noreply@blogger.com (Paul G Brown)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1934426700208076473.post-8770106502279646266</guid><pubDate>Mon, 28 Jun 2010 20:13:00 +0000</pubDate><atom:updated>2010-06-28T15:13:06.568-05:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">SqlServer</category><category domain="http://www.blogger.com/atom/ns#">Unit Testing</category><title>Quick Script to Create Constants from All Columns Names</title><description>&lt;p&gt;One thing I like to do in all my apps is create a static class that holds constants for all Column/Property names. This just avoids messing up names in places where I need to use strings. This is particularly useful when checking that attributes have been applied.&lt;/p&gt;  &lt;pre class=&quot;brush: sql;&quot;&gt;select 
     &#39;public const string &#39; + COLUMN_NAME + &#39; = &amp;quot;&#39; + COLUMN_NAME + &#39;&amp;quot;;&#39;
from INFORMATION_SCHEMA.COLUMNS
where table_Name in (&#39;Agencies&#39;, &#39;Customers&#39;)
group by COLUMN_NAME
order by COLUMN_NAME&lt;/pre&gt;

&lt;p&gt;The code produced looks like this:&lt;/p&gt;

&lt;pre class=&quot;brush: csharp;&quot;&gt;public static class ColumnNames
{
    public const string AgencyName = &amp;quot;AgencyName&amp;quot;;
    public const string CustomerName = &amp;quot;CustomerName&amp;quot;;
}&lt;/pre&gt;

&lt;p&gt;I can then refer to the name using something like&lt;/p&gt;

&lt;pre class=&quot;brush: csharp;&quot;&gt;VerifyPropertyHasAttribute(ColumnName.AgencyName, typeof(RequiredAttribute));&lt;/pre&gt;  &lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;a href=&quot;http://feeds.feedburner.com/PaulBrown&quot; title=&quot;Subscribe to my feed&quot; rel=&quot;alternate&quot; type=&quot;application/rss+xml&quot;&gt;&lt;img src=&quot;http://www.feedburner.com/fb/images/pub/feed-icon32x32.png&quot; alt=&quot;&quot; style=&quot;border:0&quot;/&gt;&lt;/a&gt;&lt;a href=&quot;http://feeds.feedburner.com/PaulBrown&quot; title=&quot;Subscribe to my feed&quot; rel=&quot;alternate&quot; type=&quot;application/rss+xml&quot;&gt;Subscribe in a reader&lt;/a&gt;&lt;/div&gt;</description><link>http://www.paulgbrown.com/2010/06/quick-script-to-create-constants-from.html</link><author>noreply@blogger.com (Paul G Brown)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1934426700208076473.post-515923034064050970</guid><pubDate>Mon, 28 Jun 2010 20:03:00 +0000</pubDate><atom:updated>2011-04-26T14:08:49.740-05:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Custom Attributes</category><category domain="http://www.blogger.com/atom/ns#">LINQ To SQL</category><category domain="http://www.blogger.com/atom/ns#">MetadataType</category><category domain="http://www.blogger.com/atom/ns#">SqlServer</category><title>Script to Create MetadataType classes</title><description>&lt;p&gt;&lt;span style=&quot;color: red;&quot;&gt;UPDATE: &lt;/span&gt;Here&#39;s the same thing for &lt;a href=&quot;http://pretzelsteelersfan.blogspot.com/2011/04/updated-code-to-get-class-definition.html&quot;&gt;EF 4.1 and Code First.&lt;/a&gt;&lt;br /&gt;
&lt;p&gt;&lt;p&gt;I’ve been using the DataAnnotations for a validation with MVC2 and Silverlight 4. They both rely on metadata (buddy) classes. The Entity Framework now will create metaclasses for you but LinqToSql didn’t get this feature.&lt;/p&gt;&lt;p&gt;This short script will create a partial class and a metaclass for the specified table. &lt;/p&gt;&lt;p&gt;&amp;#160;&lt;/p&gt;&lt;pre class=&quot;brush: sql;&quot;&gt;declare @TableName varchar(256) = &#39;Agencies&#39;
declare @EntityName varchar(256) = &#39;Agency&#39;
declare @TableSchema varchar(256) = &#39;dbo&#39;

declare @ColumnName varchar(256)
    , @DataType varchar(256)
    , @MaxLength int
    , @Nullable varchar(5)
    
declare @Lines table (Line varchar(1000))

insert into @Lines select &#39;partial class &#39; + @EntityName
insert into @Lines select &#39;{&#39;
insert into @Lines select &#39;}&#39;
insert into @Lines select &#39;public class &#39; + @EntityName + &#39;MetaClass&#39;
insert into @Lines select &#39;{&#39;

declare cols cursor for 
    select COLUMN_NAME, Data_type, CHARACTER_MAXIMUM_LENGTH, IS_NULLABLE
    from INFORMATION_SCHEMA.COLUMNS
    where table_Name = @TableName and table_schema = @Tableschema
    order by ORDINAL_POSITION

open cols

fetch next from cols into  @ColumnName, @DataType, @MaxLength, @Nullable
while @@FETCH_STATUS = 0
begin
    if @DataType in (&#39;varchar&#39;, &#39;char&#39;) and @Nullable = &#39;NO&#39;
        insert into @Lines select char(9) + &#39;[Required]&#39;
        
    if @DataType in (&#39;varchar&#39;, &#39;char&#39;)
        insert into @Lines select char(9) + &#39;[StringLength(&#39; + CAST(@MaxLength as varchar) + &#39;)]&#39;
    
    insert into @Lines select char(9) + &#39;public object &#39; + @ColumnName + &#39; { get; set; }&#39;
    
    insert into @Lines select char(9) + &#39;&#39;
    
    fetch next from cols into  @ColumnName, @DataType, @MaxLength, @Nullable
end

close cols
deallocate cols
insert into @Lines select &#39;}&#39;

select * FROM @Lines&lt;/pre&gt;&lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;a href=&quot;http://feeds.feedburner.com/PaulBrown&quot; title=&quot;Subscribe to my feed&quot; rel=&quot;alternate&quot; type=&quot;application/rss+xml&quot;&gt;&lt;img src=&quot;http://www.feedburner.com/fb/images/pub/feed-icon32x32.png&quot; alt=&quot;&quot; style=&quot;border:0&quot;/&gt;&lt;/a&gt;&lt;a href=&quot;http://feeds.feedburner.com/PaulBrown&quot; title=&quot;Subscribe to my feed&quot; rel=&quot;alternate&quot; type=&quot;application/rss+xml&quot;&gt;Subscribe in a reader&lt;/a&gt;&lt;/div&gt;</description><link>http://www.paulgbrown.com/2010/06/script-to-create-metadatatype-classes.html</link><author>noreply@blogger.com (Paul G Brown)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1934426700208076473.post-2139864909323798309</guid><pubDate>Sun, 04 Apr 2010 03:19:00 +0000</pubDate><atom:updated>2010-04-03T22:19:43.583-05:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Asp.net</category><category domain="http://www.blogger.com/atom/ns#">ModelBinder</category><category domain="http://www.blogger.com/atom/ns#">MVC</category><title>Breaking? Change In Asp.Net MVC2</title><description>&lt;p&gt;In MVC1, by default an empty textbox was sent as string.Empty to the controller on POST. In MVC2, it now sends the value as NULL. See &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.web.mvc.modelmetadata.convertemptystringtonull(VS.100).aspx&quot;&gt;ModelMetadata.ConvertEmptyStringToNull&lt;/a&gt;. I think there are some valid reasons for why they made the change – see &lt;a href=&quot;http://forums.asp.net/t/1522119.aspx&quot;&gt;Brad Wilson’s comment&lt;/a&gt; for more. If your system relies on string.Empty, you’ve got a problem. &lt;/p&gt;  &lt;p&gt;There are several options for handling this. The first is using the DisplayFormatAttribute on every property that needs it. Painful. Here’s an example:&lt;/p&gt;  &lt;pre class=&quot;brush: csharp;&quot;&gt;[DisplayFormat(ConvertEmptyStringToNull=false)]
public string FirstName { get; set; }&lt;/pre&gt;

&lt;p&gt;You can also write a custom binder that sets this value to false. Like so:&lt;/p&gt;

&lt;pre class=&quot;brush: csharp;&quot;&gt;public class CustomStringModelBinder : DefaultModelBinder 
{
    public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
    {

        var value = bindingContext.ValueProvider.GetValue(bindingContext.ModelName);   
        if (bindingContext.ModelType == typeof(string))
        {   
            bindingContext.ModelMetadata.ConvertEmptyStringToNull = false;
            if (value == null || string.IsNullOrEmpty(value.AttemptedValue))   
                return &amp;quot;&amp;quot;;
        }
        return value.AttemptedValue;
    }
}&lt;/pre&gt;

&lt;p&gt;You’ll need to add the following to the Global.asax Application_Start method to use your custom model binder.&lt;/p&gt;

&lt;pre class=&quot;brush: csharp;&quot;&gt;ModelBinders.Binders.Add(typeof(string), new CustomStringModelBinder());&lt;/pre&gt;

&lt;p&gt;One thing to note, if you use the RequiredAttribute, you don’t need to worry about the null because it will invalidate the model based on the NULL.&lt;/p&gt;

&lt;p&gt;Which option is better? Neither. Simply pick the default for ConvertEmptyStringToNull and then use DisplayFormat to handle the exceptions. Not perfect but not bad.&lt;/p&gt;

&lt;p&gt;I do wish that this was configurable in some way instead of creating a ModelBinder.&lt;/p&gt;  &lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;a href=&quot;http://feeds.feedburner.com/PaulBrown&quot; title=&quot;Subscribe to my feed&quot; rel=&quot;alternate&quot; type=&quot;application/rss+xml&quot;&gt;&lt;img src=&quot;http://www.feedburner.com/fb/images/pub/feed-icon32x32.png&quot; alt=&quot;&quot; style=&quot;border:0&quot;/&gt;&lt;/a&gt;&lt;a href=&quot;http://feeds.feedburner.com/PaulBrown&quot; title=&quot;Subscribe to my feed&quot; rel=&quot;alternate&quot; type=&quot;application/rss+xml&quot;&gt;Subscribe in a reader&lt;/a&gt;&lt;/div&gt;</description><link>http://www.paulgbrown.com/2010/04/breaking-change-in-aspnet-mvc2.html</link><author>noreply@blogger.com (Paul G Brown)</author><thr:total>1</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1934426700208076473.post-8919559855283248078</guid><pubDate>Thu, 01 Apr 2010 12:54:00 +0000</pubDate><atom:updated>2010-04-01T07:59:01.284-05:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Areas</category><category domain="http://www.blogger.com/atom/ns#">MVC</category><category domain="http://www.blogger.com/atom/ns#">Navigation</category><title>Navigation Using Areas in Asp.Net MVC</title><description>&lt;p&gt;Asp.Net MVC2 introduced Areas as a feature part of the framework. Areas allow you to divide your application into logical units. It also makes your Url’s look more accurate. &lt;/p&gt;  &lt;p&gt;Thinking of a generic store they might have areas such as Inventory, Payroll, Employees and Sales. Here are example ActionLinks for each area.&lt;/p&gt;  &lt;pre class=&quot;brush: xml;&quot;&gt;&amp;lt;%= Html.ActionLink(&amp;quot;Home&amp;quot;, &amp;quot;Index&amp;quot;, &amp;quot;Home&amp;quot;, new { area = &amp;quot;&amp;quot; }, new { })%&amp;gt;
&amp;lt;%= Html.ActionLink(&amp;quot;Payroll&amp;quot;, &amp;quot;Index&amp;quot;, &amp;quot;Main&amp;quot;, new { area = &amp;quot;Payroll&amp;quot; }, new { })%&amp;gt;
&amp;lt;%= Html.ActionLink(&amp;quot;Inventory&amp;quot;, &amp;quot;Index&amp;quot;, &amp;quot;Main&amp;quot;, new { area = &amp;quot;Inventory&amp;quot; }, new { })%&amp;gt;
&amp;lt;%= Html.ActionLink(&amp;quot;Employees&amp;quot;, &amp;quot;Index&amp;quot;, &amp;quot;Main&amp;quot;, new { area = &amp;quot;Employees&amp;quot; }, new { })%&amp;gt;
&amp;lt;%= Html.ActionLink(&amp;quot;Sales&amp;quot;, &amp;quot;Index&amp;quot;, &amp;quot;Main&amp;quot;, new { area = &amp;quot;Sales&amp;quot; }, new { })%&amp;gt;&lt;/pre&gt;

&lt;p&gt;Notice that the area is passed as a route value. I wrote my own overload for the ActionLink that takes the Area as an argument.&lt;/p&gt;

&lt;pre class=&quot;brush: csharp;&quot;&gt;public static MvcHtmlString ActionLink(this HtmlHelper helper, string linkText, string actionName, string controllerName, string areaName, object routeValues, object htmlAttributes)
{
    RouteValueDictionary routes = new RouteValueDictionary(routeValues);
    RouteValueDictionary attributes = new RouteValueDictionary(htmlAttributes);
    routes.Add(&amp;quot;area&amp;quot;, areaName);
    return helper.ActionLink(linkText, actionName, controllerName, routes, attributes);
}&lt;/pre&gt;

&lt;p&gt;This makes our links look as follows:&lt;/p&gt;

&lt;pre class=&quot;brush: xml;&quot;&gt;&amp;lt;%= Html.ActionLink(&amp;quot;Home&amp;quot;, &amp;quot;Index&amp;quot;, &amp;quot;Home&amp;quot;, &amp;quot;&amp;quot;, new { }, new { })%&amp;gt;
&amp;lt;%= Html.ActionLink(&amp;quot;Payroll&amp;quot;, &amp;quot;Index&amp;quot;, &amp;quot;Main&amp;quot;, &amp;quot;Payroll&amp;quot;, new { }, new { })%&amp;gt;
&amp;lt;%= Html.ActionLink(&amp;quot;Inventory&amp;quot;, &amp;quot;Index&amp;quot;, &amp;quot;Main&amp;quot;, &amp;quot;Inventory&amp;quot;, new { }, new { })%&amp;gt;
&amp;lt;%= Html.ActionLink(&amp;quot;Employees&amp;quot;, &amp;quot;Index&amp;quot;, &amp;quot;Main&amp;quot;, &amp;quot;Employees&amp;quot;, new { }, new { })%&amp;gt;
&amp;lt;%= Html.ActionLink(&amp;quot;Sales&amp;quot;, &amp;quot;Index&amp;quot;, &amp;quot;Main&amp;quot;, &amp;quot;Sales&amp;quot;, new { }, new { })%&amp;gt;&lt;/pre&gt;

&lt;p&gt;If you haven’t worked with Areas yet, your probably looking at the routes and noticing that each area link has a controller called Main with an Index method. You might think we’re calling the same controller and passing the area name as parameter. That is not what we are doing, each area has a controller named Main. Maybe the generated links will help.&lt;/p&gt;

&lt;pre class=&quot;brush: xml;&quot;&gt;http://somedomain.com/Payroll/Main&lt;br /&gt;
http://somedomain.com/Inventory/Main&lt;br /&gt;
http://somedomain.com/Employees/Main&lt;br /&gt;
http://somedomain.com/Sales/Main&lt;/pre&gt;

&lt;p&gt;Next thing you should notice is that the link for returning to the Home page has an empty area. We need this so that when we’re in an area we can move back up to the root. Otherwise, we’ll get a Resource Not Found error indicating showing that it’s looking for Home in that Area. This can also work in your favor. If you have a Home controller (or Main) in all of your areas, MVC will, by default, navigate within the Area and you don’t need to change your Site.Master.&lt;/p&gt;

&lt;p&gt;Overall, areas are a great feature for keeping your applications organized. &lt;/p&gt;  &lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;a href=&quot;http://feeds.feedburner.com/PaulBrown&quot; title=&quot;Subscribe to my feed&quot; rel=&quot;alternate&quot; type=&quot;application/rss+xml&quot;&gt;&lt;img src=&quot;http://www.feedburner.com/fb/images/pub/feed-icon32x32.png&quot; alt=&quot;&quot; style=&quot;border:0&quot;/&gt;&lt;/a&gt;&lt;a href=&quot;http://feeds.feedburner.com/PaulBrown&quot; title=&quot;Subscribe to my feed&quot; rel=&quot;alternate&quot; type=&quot;application/rss+xml&quot;&gt;Subscribe in a reader&lt;/a&gt;&lt;/div&gt;</description><link>http://www.paulgbrown.com/2010/04/navigation-using-areas-in-aspnet-mvc.html</link><author>noreply@blogger.com (Paul G Brown)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1934426700208076473.post-7081001713598582253</guid><pubDate>Fri, 19 Mar 2010 17:53:00 +0000</pubDate><atom:updated>2010-03-19T12:53:00.702-05:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Visual Studio</category><title>Lose your Find / Replace window?</title><description>&lt;p&gt;Working in VS2010, I suddenly lost my Find /Replace window. I found this &lt;a href=&quot;http://www.west-wind.com/Weblog/ShowPost.aspx?id=713402&quot;&gt;post&lt;/a&gt; from Rick Strahl but unfortunately that doesn’t work for me since ALT-M is mapped as a menu shortcut.&lt;/p&gt;  &lt;p&gt;Solution: Window –&amp;gt; Dock.&lt;/p&gt;  &lt;p&gt;This will dock the window and then you can move it to your desired location.&lt;/p&gt;  &lt;p&gt;Cheers!&lt;/p&gt;  &lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;a href=&quot;http://feeds.feedburner.com/PaulBrown&quot; title=&quot;Subscribe to my feed&quot; rel=&quot;alternate&quot; type=&quot;application/rss+xml&quot;&gt;&lt;img src=&quot;http://www.feedburner.com/fb/images/pub/feed-icon32x32.png&quot; alt=&quot;&quot; style=&quot;border:0&quot;/&gt;&lt;/a&gt;&lt;a href=&quot;http://feeds.feedburner.com/PaulBrown&quot; title=&quot;Subscribe to my feed&quot; rel=&quot;alternate&quot; type=&quot;application/rss+xml&quot;&gt;Subscribe in a reader&lt;/a&gt;&lt;/div&gt;</description><link>http://www.paulgbrown.com/2010/03/lose-your-find-replace-window.html</link><author>noreply@blogger.com (Paul G Brown)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1934426700208076473.post-622098851190363264</guid><pubDate>Fri, 12 Mar 2010 17:09:00 +0000</pubDate><atom:updated>2010-03-12T11:46:29.621-06:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Find / Replace</category><category domain="http://www.blogger.com/atom/ns#">Regular Expression</category><category domain="http://www.blogger.com/atom/ns#">SQL Server Management Studio</category><category domain="http://www.blogger.com/atom/ns#">Visual Studio</category><title>Visual Studio/SQL Server Management Studio Find and Replace with Regular Expressions</title><description>&lt;p&gt;I needed to format a bunch of strings in SQL Management Studio (this works for VS also) and finally took the time to figure out Find/Replace with Regular Expressions. &lt;/p&gt;  &lt;p&gt;The first thing to note is that VS/SSMS use different regex codes (don’t know why but I’m sure they have their reasons). You can find the list of codes &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/2k3te2cs(VS.100).aspx&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;I have list of 3 strings containing 10 digits followed by a space and then 3 letters. I wanted to replace the digits with the word Descriptor.&lt;/p&gt;  &lt;p&gt;Here’s my data:&lt;/p&gt;  &lt;pre&gt;1234567870 ABC
1234567880 DEF
1234567890 GHI&lt;/pre&gt;

&lt;p&gt;Here’s my find expression:&lt;/p&gt;

&lt;pre&gt;[0-9]^10 {[A-Z]^3}&lt;/pre&gt;

&lt;p&gt;Here’s my replace expression:&lt;/p&gt;

&lt;pre&gt;Descriptor: \1&lt;/pre&gt;

&lt;p&gt;Here’s my result:&lt;/p&gt;

&lt;pre&gt;Descriptor: ABC
Descriptor: DEF
Descriptor: GHI&lt;/pre&gt;

&lt;p&gt;The key is the {} brackets and \1. The {} brackets tell the engine I want to keep whatever matches the expression. This is called a Tagged Expression. The \1 says place the first tagged expression here. I can create multiple tagged expressions and place by using \1, \2, etc. I can even change the order in the result because they are numbered based on their order in the original expression. You can use newlines (\n) so that you can break lines apart). &lt;/p&gt;

&lt;p&gt;This is great for creating some testing stuff or moving non-standard data.&lt;/p&gt;

&lt;p&gt;Sweet!&lt;/p&gt;

&lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;a title=&quot;Subscribe to my feed&quot; href=&quot;http://feeds.feedburner.com/PaulBrown&quot; type=&quot;application/rss+xml&quot; rel=&quot;alternate&quot;&gt;&lt;img style=&quot;border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px&quot; alt=&quot;&quot; src=&quot;http://www.feedburner.com/fb/images/pub/feed-icon32x32.png&quot; /&gt;&lt;/a&gt;&lt;a title=&quot;Subscribe to my feed&quot; href=&quot;http://feeds.feedburner.com/PaulBrown&quot; type=&quot;application/rss+xml&quot; rel=&quot;alternate&quot;&gt;Subscribe in a reader&lt;/a&gt;&lt;/div&gt;  &lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;a href=&quot;http://feeds.feedburner.com/PaulBrown&quot; title=&quot;Subscribe to my feed&quot; rel=&quot;alternate&quot; type=&quot;application/rss+xml&quot;&gt;&lt;img src=&quot;http://www.feedburner.com/fb/images/pub/feed-icon32x32.png&quot; alt=&quot;&quot; style=&quot;border:0&quot;/&gt;&lt;/a&gt;&lt;a href=&quot;http://feeds.feedburner.com/PaulBrown&quot; title=&quot;Subscribe to my feed&quot; rel=&quot;alternate&quot; type=&quot;application/rss+xml&quot;&gt;Subscribe in a reader&lt;/a&gt;&lt;/div&gt;</description><link>http://www.paulgbrown.com/2010/03/visual-studiosql-server-management.html</link><author>noreply@blogger.com (Paul G Brown)</author><thr:total>1</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1934426700208076473.post-8299217314330605238</guid><pubDate>Tue, 22 Dec 2009 16:00:00 +0000</pubDate><atom:updated>2009-12-22T10:00:23.215-06:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Asp.net</category><category domain="http://www.blogger.com/atom/ns#">MVC</category><title>Asp.Net MVC, Forms and Missing Values</title><description>&lt;p&gt;Remember, Asp.Net requires that you use the Name and not just ID on your form controls. If you don’t, they don’t come along for the ride to your controller.&lt;/p&gt;  &lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;a href=&quot;http://feeds.feedburner.com/PaulBrown&quot; title=&quot;Subscribe to my feed&quot; rel=&quot;alternate&quot; type=&quot;application/rss+xml&quot;&gt;&lt;img src=&quot;http://www.feedburner.com/fb/images/pub/feed-icon32x32.png&quot; alt=&quot;&quot; style=&quot;border:0&quot;/&gt;&lt;/a&gt;&lt;a href=&quot;http://feeds.feedburner.com/PaulBrown&quot; title=&quot;Subscribe to my feed&quot; rel=&quot;alternate&quot; type=&quot;application/rss+xml&quot;&gt;Subscribe in a reader&lt;/a&gt;&lt;/div&gt;</description><link>http://www.paulgbrown.com/2009/12/aspnet-mvc-forms-and-missing-values.html</link><author>noreply@blogger.com (Paul G Brown)</author><thr:total>2</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1934426700208076473.post-5518678480754375686</guid><pubDate>Fri, 04 Dec 2009 16:01:00 +0000</pubDate><atom:updated>2009-12-04T10:01:43.247-06:00</atom:updated><title>RedBox “Verify Your Subscription” Emails</title><description>&lt;p&gt;Anytime I get an unsolicited email saying “verify” something, I’m suspicious. I’ve gotten three of these emails lately. Checking the links, they seem to be genuine. I also found &lt;a href=&quot;http://www.hs.facebook.com/redbox?v=feed&amp;amp;story_fbid=185214207009&amp;amp;ref=mf&quot;&gt;this&lt;/a&gt; on Facebook, that seems to indicate they are real. Did notice that lady hadn’t been able to use her code.&lt;/p&gt;  &lt;p&gt;Think I’ll give it a try and see what happens.&lt;/p&gt;  &lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;a href=&quot;http://feeds.feedburner.com/PaulBrown&quot; title=&quot;Subscribe to my feed&quot; rel=&quot;alternate&quot; type=&quot;application/rss+xml&quot;&gt;&lt;img src=&quot;http://www.feedburner.com/fb/images/pub/feed-icon32x32.png&quot; alt=&quot;&quot; style=&quot;border:0&quot;/&gt;&lt;/a&gt;&lt;a href=&quot;http://feeds.feedburner.com/PaulBrown&quot; title=&quot;Subscribe to my feed&quot; rel=&quot;alternate&quot; type=&quot;application/rss+xml&quot;&gt;Subscribe in a reader&lt;/a&gt;&lt;/div&gt;</description><link>http://www.paulgbrown.com/2009/12/redbox-verify-your-subscription-emails.html</link><author>noreply@blogger.com (Paul G Brown)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1934426700208076473.post-9192978345774660278</guid><pubDate>Mon, 23 Nov 2009 00:56:00 +0000</pubDate><atom:updated>2009-11-23T10:51:44.697-06:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Cache</category><category domain="http://www.blogger.com/atom/ns#">Compress</category><category domain="http://www.blogger.com/atom/ns#">MVC</category><title>Cache and Compress in Asp.Net MVC</title><description>&lt;p&gt;Found a &lt;a href=&quot;http://weblogs.asp.net/rashid/archive/2008/03/28/asp-net-mvc-action-filter-caching-and-compression.aspx&quot; target=&quot;_blank&quot;&gt;good entry&lt;/a&gt; on caching at the user browser and compressing the response. Note: It’s from some early beta stuff so be sure to change FilterExecutingConext to ActionExecutingContext. More on that &lt;a href=&quot;http://forums.asp.net/t/1249305.aspx&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;Enjoy!&lt;/p&gt;  &lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;a title=&quot;Subscribe to my feed&quot; href=&quot;http://feeds.feedburner.com/PaulBrown&quot; type=&quot;application/rss+xml&quot; rel=&quot;alternate&quot;&gt;&lt;img style=&quot;border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px&quot; alt=&quot;&quot; src=&quot;http://www.feedburner.com/fb/images/pub/feed-icon32x32.png&quot; /&gt;&lt;/a&gt;&lt;a title=&quot;Subscribe to my feed&quot; href=&quot;http://feeds.feedburner.com/PaulBrown&quot; type=&quot;application/rss+xml&quot; rel=&quot;alternate&quot;&gt;Subscribe in a reader&lt;/a&gt;&lt;/div&gt;  &lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;a href=&quot;http://feeds.feedburner.com/PaulBrown&quot; title=&quot;Subscribe to my feed&quot; rel=&quot;alternate&quot; type=&quot;application/rss+xml&quot;&gt;&lt;img src=&quot;http://www.feedburner.com/fb/images/pub/feed-icon32x32.png&quot; alt=&quot;&quot; style=&quot;border:0&quot;/&gt;&lt;/a&gt;&lt;a href=&quot;http://feeds.feedburner.com/PaulBrown&quot; title=&quot;Subscribe to my feed&quot; rel=&quot;alternate&quot; type=&quot;application/rss+xml&quot;&gt;Subscribe in a reader&lt;/a&gt;&lt;/div&gt;</description><link>http://www.paulgbrown.com/2009/11/cache-and-compress-in-aspnet-mvc.html</link><author>noreply@blogger.com (Paul G Brown)</author><thr:total>0</thr:total></item></channel></rss>